forked from TrueCloudLab/frostfs-api-go
Merge pull request #70 from nspcc-dev/use-token-getters-setters
service: access Token message fields through getters and setters
This commit is contained in:
commit
e47b775a86
6 changed files with 36 additions and 43 deletions
|
@ -334,14 +334,14 @@ func Stringify(dst io.Writer, obj *Object) error {
|
||||||
val = fmt.Sprintf("{"+
|
val = fmt.Sprintf("{"+
|
||||||
"ID=%s OwnerID=%s Verb=%s Address=%s Created=%d ValidUntil=%d SessionKey=%02x Signature=%02x"+
|
"ID=%s OwnerID=%s Verb=%s Address=%s Created=%d ValidUntil=%d SessionKey=%02x Signature=%02x"+
|
||||||
"}",
|
"}",
|
||||||
t.Token.Token_Info.ID,
|
t.Token.GetID(),
|
||||||
t.Token.Token_Info.OwnerID,
|
t.Token.GetOwnerID(),
|
||||||
t.Token.Token_Info.Verb,
|
t.Token.GetVerb(),
|
||||||
t.Token.Token_Info.Address,
|
t.Token.GetAddress(),
|
||||||
t.Token.Token_Info.Created,
|
t.Token.CreationEpoch(),
|
||||||
t.Token.Token_Info.ValidUntil,
|
t.Token.ExpirationEpoch(),
|
||||||
t.Token.Token_Info.SessionKey,
|
t.Token.GetSessionKey(),
|
||||||
t.Token.Signature)
|
t.Token.GetSignature())
|
||||||
case *Header_HomoHash:
|
case *Header_HomoHash:
|
||||||
key = "HomoHash"
|
key = "HomoHash"
|
||||||
val = t.HomoHash
|
val = t.HomoHash
|
||||||
|
|
|
@ -111,21 +111,20 @@ Object:
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
token := new(Token)
|
||||||
|
token.SetID(oid)
|
||||||
|
token.SetOwnerID(uid)
|
||||||
|
token.SetVerb(service.Token_Info_Search)
|
||||||
|
token.SetAddress(Address{ObjectID: oid, CID: refs.CID{}})
|
||||||
|
token.SetCreationEpoch(1)
|
||||||
|
token.SetExpirationEpoch(2)
|
||||||
|
token.SetSessionKey([]byte{1, 2, 3, 4, 5, 6})
|
||||||
|
token.SetSignature([]byte{1, 2, 3, 4, 5, 6})
|
||||||
|
|
||||||
// *Header_Token
|
// *Header_Token
|
||||||
obj.Headers = append(obj.Headers, Header{
|
obj.Headers = append(obj.Headers, Header{
|
||||||
Value: &Header_Token{
|
Value: &Header_Token{
|
||||||
Token: &Token{
|
Token: token,
|
||||||
Signature: []byte{1, 2, 3, 4, 5, 6},
|
|
||||||
Token_Info: service.Token_Info{
|
|
||||||
ID: oid,
|
|
||||||
OwnerID: uid,
|
|
||||||
Verb: service.Token_Info_Search,
|
|
||||||
Address: service.Address{ObjectID: oid, CID: refs.CID{}},
|
|
||||||
Created: 1,
|
|
||||||
ValidUntil: 2,
|
|
||||||
SessionKey: []byte{1, 2, 3, 4, 5, 6},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ func (m Object) Verify() error {
|
||||||
}
|
}
|
||||||
pubkey = pkh.Value.(*Header_PublicKey).PublicKey.Value
|
pubkey = pkh.Value.(*Header_PublicKey).PublicKey.Value
|
||||||
} else {
|
} else {
|
||||||
pubkey = vh.Value.(*Header_Token).Token.SessionKey
|
pubkey = vh.Value.(*Header_Token).Token.GetSessionKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify signature
|
// Verify signature
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/nspcc-dev/neofs-api-go/container"
|
"github.com/nspcc-dev/neofs-api-go/container"
|
||||||
"github.com/nspcc-dev/neofs-api-go/refs"
|
"github.com/nspcc-dev/neofs-api-go/refs"
|
||||||
"github.com/nspcc-dev/neofs-api-go/service"
|
|
||||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||||
"github.com/nspcc-dev/neofs-crypto/test"
|
"github.com/nspcc-dev/neofs-crypto/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -77,12 +76,9 @@ func TestObject_Verify(t *testing.T) {
|
||||||
|
|
||||||
dataPK := crypto.MarshalPublicKey(&sessionkey.PublicKey)
|
dataPK := crypto.MarshalPublicKey(&sessionkey.PublicKey)
|
||||||
signature, err = crypto.Sign(key, dataPK)
|
signature, err = crypto.Sign(key, dataPK)
|
||||||
tok := &service.Token{
|
tok := new(Token)
|
||||||
Token_Info: service.Token_Info{
|
tok.SetSignature(signature)
|
||||||
SessionKey: dataPK,
|
tok.SetSessionKey(dataPK)
|
||||||
},
|
|
||||||
Signature: signature,
|
|
||||||
}
|
|
||||||
obj.AddHeader(&Header{Value: &Header_Token{Token: tok}})
|
obj.AddHeader(&Header{Value: &Header_Token{Token: tok}})
|
||||||
|
|
||||||
// validation header is not last
|
// validation header is not last
|
||||||
|
|
|
@ -194,7 +194,7 @@ func TestRequestVerificationHeader_SetToken(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
token := new(Token)
|
token := new(Token)
|
||||||
token.ID = id
|
token.SetID(id)
|
||||||
|
|
||||||
h := new(RequestVerificationHeader)
|
h := new(RequestVerificationHeader)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/refs"
|
"github.com/nspcc-dev/neofs-api-go/refs"
|
||||||
"github.com/nspcc-dev/neofs-api-go/service"
|
|
||||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,24 +45,23 @@ func (s *simpleStore) New(p TokenParams) *PToken {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
token := new(Token)
|
||||||
|
token.SetID(tid)
|
||||||
|
token.SetOwnerID(p.OwnerID)
|
||||||
|
token.SetVerb(p.Verb)
|
||||||
|
token.SetAddress(p.Address)
|
||||||
|
token.SetCreationEpoch(p.FirstEpoch)
|
||||||
|
token.SetExpirationEpoch(p.LastEpoch)
|
||||||
|
token.SetSessionKey(crypto.MarshalPublicKey(&key.PublicKey))
|
||||||
|
|
||||||
t := &PToken{
|
t := &PToken{
|
||||||
mtx: new(sync.Mutex),
|
mtx: new(sync.Mutex),
|
||||||
Token: Token{
|
Token: *token,
|
||||||
Token_Info: service.Token_Info{
|
|
||||||
ID: tid,
|
|
||||||
OwnerID: p.OwnerID,
|
|
||||||
Verb: p.Verb,
|
|
||||||
Address: p.Address,
|
|
||||||
Created: p.FirstEpoch,
|
|
||||||
ValidUntil: p.LastEpoch,
|
|
||||||
SessionKey: crypto.MarshalPublicKey(&key.PublicKey),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
PrivateKey: key,
|
PrivateKey: key,
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Lock()
|
s.Lock()
|
||||||
s.tokens[t.ID] = t
|
s.tokens[tid] = t
|
||||||
s.Unlock()
|
s.Unlock()
|
||||||
|
|
||||||
return t
|
return t
|
||||||
|
|
Loading…
Reference in a new issue