added shamir keys
This commit is contained in:
parent
13780f1c74
commit
be0f532628
14 changed files with 238 additions and 43 deletions
|
|
@ -27,7 +27,7 @@ func GenerateID() (string, error) {
|
|||
return hex.EncodeToString(id), nil
|
||||
}
|
||||
|
||||
func Generate(name string, size int, enc core.Encoding) (k core.Key, err error) {
|
||||
func Generate(name string, size int, enc core.Encoding, t core.Type) (kstore, k core.Key, err error) {
|
||||
id, err := GenerateID()
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -36,13 +36,24 @@ func Generate(name string, size int, enc core.Encoding) (k core.Key, err error)
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
k = core.Key{
|
||||
key, err = t.Encode(key)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
kstore = core.Key{
|
||||
Name: name,
|
||||
ID: id,
|
||||
Size: size,
|
||||
Encoding: enc,
|
||||
Key: enc.EncodeToString(key),
|
||||
Type: t,
|
||||
Created: time.Now().Unix(),
|
||||
}
|
||||
k = kstore
|
||||
if t == core.Shamir {
|
||||
klen := len(key) / 2
|
||||
k.Key = core.Hex.EncodeToString(key[klen:])
|
||||
key = key[0:klen]
|
||||
}
|
||||
kstore.Key = enc.EncodeToString(key)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue