service: access Token message fields through getters and setters

This commit is contained in:
Leonard Lyubich 2020-04-28 18:40:21 +03:00
parent 091f953ebf
commit c6971d2004
6 changed files with 36 additions and 43 deletions

View file

@ -334,14 +334,14 @@ func Stringify(dst io.Writer, obj *Object) error {
val = fmt.Sprintf("{"+
"ID=%s OwnerID=%s Verb=%s Address=%s Created=%d ValidUntil=%d SessionKey=%02x Signature=%02x"+
"}",
t.Token.Token_Info.ID,
t.Token.Token_Info.OwnerID,
t.Token.Token_Info.Verb,
t.Token.Token_Info.Address,
t.Token.Token_Info.Created,
t.Token.Token_Info.ValidUntil,
t.Token.Token_Info.SessionKey,
t.Token.Signature)
t.Token.GetID(),
t.Token.GetOwnerID(),
t.Token.GetVerb(),
t.Token.GetAddress(),
t.Token.CreationEpoch(),
t.Token.ExpirationEpoch(),
t.Token.GetSessionKey(),
t.Token.GetSignature())
case *Header_HomoHash:
key = "HomoHash"
val = t.HomoHash

View file

@ -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
obj.Headers = append(obj.Headers, Header{
Value: &Header_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},
},
},
Token: token,
},
})

View file

@ -85,7 +85,7 @@ func (m Object) Verify() error {
}
pubkey = pkh.Value.(*Header_PublicKey).PublicKey.Value
} else {
pubkey = vh.Value.(*Header_Token).Token.SessionKey
pubkey = vh.Value.(*Header_Token).Token.GetSessionKey()
}
// Verify signature

View file

@ -6,7 +6,6 @@ import (
"github.com/google/uuid"
"github.com/nspcc-dev/neofs-api-go/container"
"github.com/nspcc-dev/neofs-api-go/refs"
"github.com/nspcc-dev/neofs-api-go/service"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-crypto/test"
"github.com/stretchr/testify/require"
@ -77,12 +76,9 @@ func TestObject_Verify(t *testing.T) {
dataPK := crypto.MarshalPublicKey(&sessionkey.PublicKey)
signature, err = crypto.Sign(key, dataPK)
tok := &service.Token{
Token_Info: service.Token_Info{
SessionKey: dataPK,
},
Signature: signature,
}
tok := new(Token)
tok.SetSignature(signature)
tok.SetSessionKey(dataPK)
obj.AddHeader(&Header{Value: &Header_Token{Token: tok}})
// validation header is not last

View file

@ -194,7 +194,7 @@ func TestRequestVerificationHeader_SetToken(t *testing.T) {
require.NoError(t, err)
token := new(Token)
token.ID = id
token.SetID(id)
h := new(RequestVerificationHeader)

View file

@ -7,7 +7,6 @@ import (
"sync"
"github.com/nspcc-dev/neofs-api-go/refs"
"github.com/nspcc-dev/neofs-api-go/service"
crypto "github.com/nspcc-dev/neofs-crypto"
)
@ -46,24 +45,23 @@ func (s *simpleStore) New(p TokenParams) *PToken {
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{
mtx: new(sync.Mutex),
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),
},
},
mtx: new(sync.Mutex),
Token: *token,
PrivateKey: key,
}
s.Lock()
s.tokens[t.ID] = t
s.tokens[tid] = t
s.Unlock()
return t