github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/refs/types.go (about)

     1  package refs
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  )
     7  
     8  type OwnerID struct {
     9  	val []byte
    10  }
    11  
    12  type ContainerID struct {
    13  	val []byte
    14  }
    15  
    16  type ObjectID struct {
    17  	val []byte
    18  }
    19  
    20  type Address struct {
    21  	cid *ContainerID
    22  
    23  	oid *ObjectID
    24  }
    25  
    26  type Checksum struct {
    27  	typ ChecksumType
    28  
    29  	sum []byte
    30  }
    31  
    32  type ChecksumType uint32
    33  
    34  type SignatureScheme uint32
    35  
    36  //nolint:revive
    37  const (
    38  	ECDSA_SHA512 SignatureScheme = iota
    39  	ECDSA_RFC6979_SHA256
    40  	ECDSA_RFC6979_SHA256_WALLET_CONNECT
    41  )
    42  
    43  type Signature struct {
    44  	key, sign []byte
    45  	scheme    SignatureScheme
    46  }
    47  
    48  type SubnetID struct {
    49  	value uint32
    50  }
    51  
    52  type Version struct {
    53  	major, minor uint32
    54  }
    55  
    56  const (
    57  	UnknownChecksum ChecksumType = iota
    58  	TillichZemor
    59  	SHA256
    60  )
    61  
    62  func (o *OwnerID) GetValue() []byte {
    63  	if o != nil {
    64  		return o.val
    65  	}
    66  
    67  	return nil
    68  }
    69  
    70  func (o *OwnerID) SetValue(v []byte) {
    71  	o.val = v
    72  }
    73  
    74  func (c *ContainerID) GetValue() []byte {
    75  	if c != nil {
    76  		return c.val
    77  	}
    78  
    79  	return nil
    80  }
    81  
    82  func (c *ContainerID) SetValue(v []byte) {
    83  	c.val = v
    84  }
    85  
    86  func (o *ObjectID) GetValue() []byte {
    87  	if o != nil {
    88  		return o.val
    89  	}
    90  
    91  	return nil
    92  }
    93  
    94  func (o *ObjectID) SetValue(v []byte) {
    95  	o.val = v
    96  }
    97  
    98  func (a *Address) GetContainerID() *ContainerID {
    99  	if a != nil {
   100  		return a.cid
   101  	}
   102  
   103  	return nil
   104  }
   105  
   106  func (a *Address) SetContainerID(v *ContainerID) {
   107  	a.cid = v
   108  }
   109  
   110  func (a *Address) GetObjectID() *ObjectID {
   111  	if a != nil {
   112  		return a.oid
   113  	}
   114  
   115  	return nil
   116  }
   117  
   118  func (a *Address) SetObjectID(v *ObjectID) {
   119  	a.oid = v
   120  }
   121  
   122  func (c *Checksum) GetType() ChecksumType {
   123  	if c != nil {
   124  		return c.typ
   125  	}
   126  
   127  	return UnknownChecksum
   128  }
   129  
   130  func (c *Checksum) SetType(v ChecksumType) {
   131  	c.typ = v
   132  }
   133  
   134  func (c *Checksum) GetSum() []byte {
   135  	if c != nil {
   136  		return c.sum
   137  	}
   138  
   139  	return nil
   140  }
   141  
   142  func (c *Checksum) SetSum(v []byte) {
   143  	c.sum = v
   144  }
   145  
   146  func (s *Signature) GetKey() []byte {
   147  	if s != nil {
   148  		return s.key
   149  	}
   150  
   151  	return nil
   152  }
   153  
   154  func (s *Signature) SetKey(v []byte) {
   155  	s.key = v
   156  }
   157  
   158  func (s *Signature) GetSign() []byte {
   159  	if s != nil {
   160  		return s.sign
   161  	}
   162  
   163  	return nil
   164  }
   165  
   166  func (s *Signature) SetSign(v []byte) {
   167  	s.sign = v
   168  }
   169  
   170  func (s *Signature) GetScheme() SignatureScheme {
   171  	if s != nil {
   172  		return s.scheme
   173  	}
   174  	return 0
   175  }
   176  
   177  func (s *Signature) SetScheme(scheme SignatureScheme) {
   178  	s.scheme = scheme
   179  }
   180  
   181  func (s *SubnetID) SetValue(id uint32) {
   182  	s.value = id
   183  }
   184  
   185  func (s *SubnetID) GetValue() uint32 {
   186  	if s != nil {
   187  		return s.value
   188  	}
   189  	return 0
   190  }
   191  
   192  // MarshalText encodes SubnetID into text format according to NeoFS API V2 protocol:
   193  // value in base-10 integer string format.
   194  //
   195  // Implements encoding.TextMarshaler.
   196  func (s *SubnetID) MarshalText() ([]byte, error) {
   197  	num := s.GetValue() // NPE safe, returns zero on nil (zero subnet)
   198  
   199  	return []byte(strconv.FormatUint(uint64(num), 10)), nil
   200  }
   201  
   202  // UnmarshalText decodes SubnetID from the text according to NeoFS API V2 protocol:
   203  // should be base-10 integer string format with bitsize = 32.
   204  //
   205  // Returns strconv.ErrRange if integer overflows uint32.
   206  //
   207  // Must not be called on nil.
   208  //
   209  // Implements encoding.TextUnmarshaler.
   210  func (s *SubnetID) UnmarshalText(txt []byte) error {
   211  	num, err := strconv.ParseUint(string(txt), 10, 32)
   212  	if err != nil {
   213  		return fmt.Errorf("invalid numeric value: %w", err)
   214  	}
   215  
   216  	s.value = uint32(num)
   217  
   218  	return nil
   219  }
   220  
   221  // IsZeroSubnet returns true iff the SubnetID refers to zero subnet.
   222  func IsZeroSubnet(id *SubnetID) bool {
   223  	return id.GetValue() == 0
   224  }
   225  
   226  // MakeZeroSubnet makes the SubnetID to refer to zero subnet.
   227  func MakeZeroSubnet(id *SubnetID) {
   228  	id.SetValue(0)
   229  }
   230  
   231  func (v *Version) GetMajor() uint32 {
   232  	if v != nil {
   233  		return v.major
   234  	}
   235  
   236  	return 0
   237  }
   238  
   239  func (v *Version) SetMajor(val uint32) {
   240  	v.major = val
   241  }
   242  
   243  func (v *Version) GetMinor() uint32 {
   244  	if v != nil {
   245  		return v.minor
   246  	}
   247  
   248  	return 0
   249  }
   250  
   251  func (v *Version) SetMinor(val uint32) {
   252  	v.minor = val
   253  }