2020-09-01 13:11:38 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
2020-09-11 15:18:29 +00:00
|
|
|
"bytes"
|
2020-09-01 13:11:38 +00:00
|
|
|
"crypto/sha256"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
|
|
|
)
|
|
|
|
|
2020-09-10 09:57:29 +00:00
|
|
|
// ID represents v2-compatible object identifier.
|
|
|
|
type ID refs.ObjectID
|
|
|
|
|
|
|
|
// NewIDFromV2 wraps v2 ObjectID message to ID.
|
|
|
|
func NewIDFromV2(idV2 *refs.ObjectID) *ID {
|
|
|
|
return (*ID)(idV2)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewID creates and initializes blank ID.
|
|
|
|
//
|
|
|
|
// Works similar as NewIDFromV2(new(ObjectID)).
|
|
|
|
func NewID() *ID {
|
|
|
|
return NewIDFromV2(new(refs.ObjectID))
|
2020-09-01 13:11:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetSHA256 sets object identifier value to SHA256 checksum.
|
|
|
|
func (id *ID) SetSHA256(v [sha256.Size]byte) {
|
2020-09-10 09:57:29 +00:00
|
|
|
(*refs.ObjectID)(id).SetValue(v[:])
|
2020-09-01 13:11:38 +00:00
|
|
|
}
|
|
|
|
|
2020-09-11 15:18:29 +00:00
|
|
|
// Equal returns true if identifiers are identical.
|
|
|
|
func (id *ID) Equal(id2 *ID) bool {
|
|
|
|
return bytes.Equal(
|
|
|
|
(*ID)(id).ToV2().GetValue(),
|
|
|
|
(*ID)(id2).ToV2().GetValue(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-09-01 13:11:38 +00:00
|
|
|
// ToV2 converts ID to v2 ObjectID message.
|
|
|
|
func (id *ID) ToV2() *refs.ObjectID {
|
2020-09-10 09:57:29 +00:00
|
|
|
return (*refs.ObjectID)(id)
|
2020-09-01 13:11:38 +00:00
|
|
|
}
|