1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-09 09:35:03 +09:00

Add generated read keys

This commit is contained in:
mcrakhman 2022-08-21 17:43:22 +02:00 committed by Mikhail Iudin
parent 1ab430d088
commit 28f4f03dff
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0
2 changed files with 17 additions and 2 deletions

View file

@ -25,4 +25,4 @@ keys:
value: 3iiLPj6wMUQpPwTBNZcUgkbXub1jumg4AEV9LfMyFHZVc84GLyAjVbVvH6EAGhcNrxRxL82aW4BimhDZCpLsRCqx5vwj
Read:
- name: 1
value: generated
value: bamccoi5jdypwnjkiuuogkawvhkbowha4qg756uhnbkecr5vt3h4q

View file

@ -111,7 +111,22 @@ func (k *Keychain) AddReadKey(key *Key) {
if _, exists := k.ReadKeys[key.Name]; exists {
return
}
rkey, _ := symmetric.NewRandom()
var (
rkey *symmetric.Key
err error
)
if key.Value == "generated" {
rkey, err = symmetric.NewRandom()
if err != nil {
panic("should be able to generate symmetric key")
}
} else {
rkey, err = symmetric.FromString(key.Value)
if err != nil {
panic("should be able to parse symmetric key")
}
}
hasher := fnv.New64()
hasher.Write(rkey.Bytes())