2021-05-25 19:59:21 +00:00
|
|
|
package accessbox
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/token"
|
|
|
|
)
|
|
|
|
|
|
|
|
type bearerBox struct {
|
|
|
|
tkn *token.BearerToken
|
|
|
|
}
|
|
|
|
|
2021-05-26 18:23:36 +00:00
|
|
|
// NewBearerBox wraps given bearer token into BearerTokenBox.
|
2021-05-25 19:59:21 +00:00
|
|
|
func NewBearerBox(token *token.BearerToken) BearerTokenBox {
|
|
|
|
return &bearerBox{tkn: token}
|
|
|
|
}
|
|
|
|
|
2021-05-26 18:23:36 +00:00
|
|
|
// Marshal serializes bearer token.
|
2021-05-25 19:59:21 +00:00
|
|
|
func (b *bearerBox) Marshal() ([]byte, error) {
|
|
|
|
return b.tkn.Marshal(nil)
|
|
|
|
}
|
|
|
|
|
2021-05-26 18:23:36 +00:00
|
|
|
// Marshal initializes bearer box from its serialized representation.
|
2021-05-25 19:59:21 +00:00
|
|
|
func (b *bearerBox) Unmarshal(data []byte) error {
|
|
|
|
tkn := token.NewBearerToken()
|
|
|
|
|
|
|
|
err := tkn.Unmarshal(data)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
b.SetToken(tkn)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-05-26 18:23:36 +00:00
|
|
|
// Token unwraps bearer token from the box.
|
2021-05-25 19:59:21 +00:00
|
|
|
func (b *bearerBox) Token() *token.BearerToken {
|
|
|
|
return b.tkn
|
|
|
|
}
|
|
|
|
|
2021-05-26 18:23:36 +00:00
|
|
|
// SetToken sets new token in the box.
|
2021-05-25 19:59:21 +00:00
|
|
|
func (b *bearerBox) SetToken(tkn *token.BearerToken) {
|
|
|
|
b.tkn = tkn
|
|
|
|
}
|