forked from cwtch.im/cwtch
Merge branch 'fix-lint' of dan/cwtch into master
This commit is contained in:
commit
8a1fb3ccc2
|
@ -108,7 +108,7 @@ func encryptProfile(p *cwtchPeer, key [32]byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
//decryptProfile decrypts the passed ciphertext into a cwtchPeer via the specified key.
|
//decryptProfile decrypts the passed ciphertext into a cwtchPeer via the specified key.
|
||||||
func decryptProfile(ciphertext []byte, key [32]byte) (error, *cwtchPeer) {
|
func decryptProfile(ciphertext []byte, key [32]byte) (*cwtchPeer, error) {
|
||||||
|
|
||||||
var decryptNonce [24]byte
|
var decryptNonce [24]byte
|
||||||
copy(decryptNonce[:], ciphertext[:24])
|
copy(decryptNonce[:], ciphertext[:24])
|
||||||
|
@ -117,12 +117,11 @@ func decryptProfile(ciphertext []byte, key [32]byte) (error, *cwtchPeer) {
|
||||||
cp := &cwtchPeer{}
|
cp := &cwtchPeer{}
|
||||||
err := json.Unmarshal(decrypted, &cp)
|
err := json.Unmarshal(decrypted, &cp)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil, cp
|
return cp, nil
|
||||||
} else {
|
|
||||||
return err, nil
|
|
||||||
}
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Failed to decrypt"), nil
|
return nil, fmt.Errorf("Failed to decrypt")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *cwtchPeer) setup() {
|
func (cp *cwtchPeer) setup() {
|
||||||
|
@ -184,16 +183,15 @@ func LoadCwtchPeer(profilefile string, password string) (CwtchPeerInterface, err
|
||||||
copy(dkr[:], dk)
|
copy(dkr[:], dk)
|
||||||
copy(salty[:], salt)
|
copy(salty[:], salt)
|
||||||
|
|
||||||
err, cp := decryptProfile(encryptedbytes, dkr)
|
cp, err := decryptProfile(encryptedbytes, dkr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cp.setup()
|
cp.setup()
|
||||||
cp.profilefile = profilefile
|
cp.profilefile = profilefile
|
||||||
cp.key = dkr
|
cp.key = dkr
|
||||||
cp.salt = salty
|
cp.salt = salty
|
||||||
return cp, nil
|
return cp, nil
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImportGroup intializes a group from an imported source rather than a peer invite
|
// ImportGroup intializes a group from an imported source rather than a peer invite
|
||||||
|
|
Loading…
Reference in New Issue