2019-06-27 18:36:51 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package mobile
|
|
|
|
|
|
|
|
import (
|
|
|
|
libuplink "storj.io/storj/lib/uplink"
|
|
|
|
"storj.io/storj/pkg/storj"
|
|
|
|
)
|
|
|
|
|
2019-06-28 06:18:24 +01:00
|
|
|
// EncryptionAccess holds data about encryption keys for a bucket.
|
|
|
|
type EncryptionAccess struct {
|
|
|
|
lib *libuplink.EncryptionAccess
|
2019-06-27 18:36:51 +01:00
|
|
|
}
|
|
|
|
|
2019-06-28 06:18:24 +01:00
|
|
|
// NewEncryptionAccess constructs an empty encryption context.
|
|
|
|
func NewEncryptionAccess() *EncryptionAccess {
|
|
|
|
return &EncryptionAccess{lib: libuplink.NewEncryptionAccess()}
|
2019-06-27 18:36:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetDefaultKey sets the default key to use when no matching keys are found
|
|
|
|
// for the encryption context.
|
2019-06-28 06:18:24 +01:00
|
|
|
func (e *EncryptionAccess) SetDefaultKey(keyData []byte) error {
|
2019-06-27 18:36:51 +01:00
|
|
|
key, err := storj.NewKey(keyData)
|
|
|
|
if err != nil {
|
|
|
|
return safeError(err)
|
|
|
|
}
|
|
|
|
e.lib.SetDefaultKey(*key)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-06-28 06:18:24 +01:00
|
|
|
// ParseEncryptionAccess parses the base58 encoded encryption context data and
|
2019-06-27 18:36:51 +01:00
|
|
|
// returns the resulting context.
|
2019-06-28 06:18:24 +01:00
|
|
|
func ParseEncryptionAccess(b58data string) (*EncryptionAccess, error) {
|
|
|
|
access, err := libuplink.ParseEncryptionAccess(b58data)
|
2019-06-27 18:36:51 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, safeError(err)
|
|
|
|
}
|
2019-06-28 06:18:24 +01:00
|
|
|
return &EncryptionAccess{lib: access}, nil
|
2019-06-27 18:36:51 +01:00
|
|
|
}
|