Skip to content

Commit

Permalink
fix namings
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Oct 17, 2024
1 parent 7ad5bcf commit cc0751c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions share/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (n *Namespace) UnmarshalJSON(data []byte) error {
// This should be used for user specified namespaces.
func NewNamespace(version uint8, id []byte) (Namespace, error) {
ns := newNamespace(version, id)
if err := ns.ValidateUserNamespace(); err != nil {
if err := ns.validate(); err != nil {
return Namespace{}, err
}
return ns, nil
Expand Down Expand Up @@ -71,7 +71,7 @@ func NewNamespaceFromBytes(bytes []byte) (Namespace, error) {
}

ns := Namespace{data: bytes}
if err := ns.ValidateUserNamespace(); err != nil {
if err := ns.validate(); err != nil {
return Namespace{}, err
}
return ns, nil
Expand Down Expand Up @@ -121,11 +121,11 @@ func (n Namespace) String() string {
return hex.EncodeToString(n.data)
}

// ValidateUserNamespace returns an error if the provided version is not
// validate returns an error if the provided version is not
// supported or the provided id does not meet the requirements
// for the provided version. This should be used for validating
// user specified namespaces
func (n Namespace) ValidateUserNamespace() error {
func (n Namespace) validate() error {
err := n.validateVersionSupported()
if err != nil {
return err
Expand All @@ -141,12 +141,20 @@ func (n Namespace) ValidateForData() error {
return nil
}

// ValidateForBlob checks if the Namespace is a valid blob namespace.
// ValidateForBlob verifies whether the Namespace is appropriate for blob data.
// A valid blob namespace must meet two conditions: it cannot be reserved for special purposes,
// and its version must be supported by the system. If either of these conditions is not met,
// an error is returned indicating the issue. This ensures that only valid namespaces are
// used when dealing with blob data.
func (n Namespace) ValidateForBlob() error {
if err := n.ValidateForData(); err != nil {
return err
}

if n.IsReserved() {
return fmt.Errorf("invalid data namespace(%s): reserved data is forbidden", n)
}

if !slices.Contains(SupportedBlobNamespaceVersions, n.Version()) {
return fmt.Errorf("blob version %d is not supported", n.Version())
}
Expand Down

0 comments on commit cc0751c

Please sign in to comment.