forked from TrueCloudLab/frostfs-sdk-go
[#170] oid, cid: Add marshal format checks
Also add checking presence of the `oid`, `cid` fields via `set` flag. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
f7172adf18
commit
1186f2f703
17 changed files with 432 additions and 118 deletions
|
@ -88,7 +88,12 @@ func VerifyID(obj *Object) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if !id.Equals(obj.ID()) {
|
||||
oID, set := obj.ID()
|
||||
if !set {
|
||||
return errOIDNotSet
|
||||
}
|
||||
|
||||
if !id.Equals(oID) {
|
||||
return errIncorrectID
|
||||
}
|
||||
|
||||
|
@ -98,7 +103,12 @@ func VerifyID(obj *Object) error {
|
|||
// CalculateAndSetSignature signs id with provided key and sets that signature to
|
||||
// the object.
|
||||
func CalculateAndSetSignature(key ecdsa.PrivateKey, obj *Object) error {
|
||||
sig, err := obj.ID().CalculateIDSignature(key)
|
||||
oID, set := obj.ID()
|
||||
if !set {
|
||||
return errOIDNotSet
|
||||
}
|
||||
|
||||
sig, err := oID.CalculateIDSignature(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -110,8 +120,13 @@ func CalculateAndSetSignature(key ecdsa.PrivateKey, obj *Object) error {
|
|||
|
||||
// VerifyIDSignature verifies object ID signature.
|
||||
func (o *Object) VerifyIDSignature() bool {
|
||||
oID, set := o.ID()
|
||||
if !set {
|
||||
return false
|
||||
}
|
||||
|
||||
var idV2 refs.ObjectID
|
||||
o.ID().WriteToV2(&idV2)
|
||||
oID.WriteToV2(&idV2)
|
||||
|
||||
sig := o.Signature()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue