Commit ed5f0404 authored by Łukasz Magiera's avatar Łukasz Magiera

coreapi: key tests

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent 8f7e0241
...@@ -148,13 +148,13 @@ type KeyAPI interface { ...@@ -148,13 +148,13 @@ type KeyAPI interface {
// name and returns a base58 encoded multihash of it's public key // name and returns a base58 encoded multihash of it's public key
Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (Key, error) Generate(ctx context.Context, name string, opts ...options.KeyGenerateOption) (Key, error)
// WithAlgorithm is an option for Generate which specifies which algorithm // WithType is an option for Generate which specifies which algorithm
// should be used for the key. Default is options.RSAKey // should be used for the key. Default is options.RSAKey
// //
// Supported algorithms: // Supported key types:
// * options.RSAKey // * options.RSAKey
// * options.Ed25519Key // * options.Ed25519Key
WithAlgorithm(algorithm string) options.KeyGenerateOption WithType(algorithm string) options.KeyGenerateOption
// WithSize is an option for Generate which specifies the size of the key to // WithSize is an option for Generate which specifies the size of the key to
// generated. Default is 0 // generated. Default is 0
......
...@@ -3,6 +3,8 @@ package options ...@@ -3,6 +3,8 @@ package options
const ( const (
RSAKey = "rsa" RSAKey = "rsa"
Ed25519Key = "ed25519" Ed25519Key = "ed25519"
DefaultRSALen = 2048
) )
type KeyGenerateSettings struct { type KeyGenerateSettings struct {
...@@ -20,7 +22,7 @@ type KeyRenameOption func(*KeyRenameSettings) error ...@@ -20,7 +22,7 @@ type KeyRenameOption func(*KeyRenameSettings) error
func KeyGenerateOptions(opts ...KeyGenerateOption) (*KeyGenerateSettings, error) { func KeyGenerateOptions(opts ...KeyGenerateOption) (*KeyGenerateSettings, error) {
options := &KeyGenerateSettings{ options := &KeyGenerateSettings{
Algorithm: RSAKey, Algorithm: RSAKey,
Size: 0, Size: -1,
} }
for _, opt := range opts { for _, opt := range opts {
...@@ -48,7 +50,7 @@ func KeyRenameOptions(opts ...KeyRenameOption) (*KeyRenameSettings, error) { ...@@ -48,7 +50,7 @@ func KeyRenameOptions(opts ...KeyRenameOption) (*KeyRenameSettings, error) {
type KeyOptions struct{} type KeyOptions struct{}
func (api *KeyOptions) WithAlgorithm(algorithm string) KeyGenerateOption { func (api *KeyOptions) WithType(algorithm string) KeyGenerateOption {
return func(settings *KeyGenerateSettings) error { return func(settings *KeyGenerateSettings) error {
settings.Algorithm = algorithm settings.Algorithm = algorithm
return nil return nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment