forked from Silverfish/proton-bridge
Other: remove dead code
This commit is contained in:
@ -279,26 +279,6 @@ func (u *User) GetStoreAddresses() []string {
|
|||||||
return u.creds.EmailList()
|
return u.creds.EmailList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// getStoreAddresses returns a user's used addresses (with the original address in first place).
|
|
||||||
func (u *User) getStoreAddresses() []string { // nolint[unused]
|
|
||||||
addrInfo, err := u.store.GetAddressInfo()
|
|
||||||
if err != nil {
|
|
||||||
u.log.WithError(err).Error("Failed getting address info from store")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
addresses := []string{}
|
|
||||||
for _, addr := range addrInfo {
|
|
||||||
addresses = append(addresses, addr.Address)
|
|
||||||
}
|
|
||||||
|
|
||||||
if u.IsCombinedAddressMode() {
|
|
||||||
return addresses[:1]
|
|
||||||
}
|
|
||||||
|
|
||||||
return addresses
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAddresses returns list of all addresses.
|
// GetAddresses returns list of all addresses.
|
||||||
func (u *User) GetAddresses() []string {
|
func (u *User) GetAddresses() []string {
|
||||||
u.lock.RLock()
|
u.lock.RLock()
|
||||||
|
|||||||
@ -64,29 +64,6 @@ var errVerificationFailed = errors.New("signature verification failed")
|
|||||||
|
|
||||||
// ================= Public utility functions ======================
|
// ================= Public utility functions ======================
|
||||||
|
|
||||||
func (c *client) EncryptAndSignCards(cards []Card) ([]Card, error) {
|
|
||||||
var err error
|
|
||||||
for i := range cards {
|
|
||||||
card := &cards[i]
|
|
||||||
if isEncryptedCardType(card.Type) {
|
|
||||||
if isSignedCardType(card.Type) {
|
|
||||||
if card.Signature, err = c.sign(card.Data); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if card.Data, err = c.encrypt(card.Data, nil); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else if isSignedCardType(card.Type) {
|
|
||||||
if card.Signature, err = c.sign(card.Data); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cards, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *client) DecryptAndVerifyCards(cards []Card) ([]Card, error) {
|
func (c *client) DecryptAndVerifyCards(cards []Card) ([]Card, error) {
|
||||||
for i := range cards {
|
for i := range cards {
|
||||||
card := &cards[i]
|
card := &cards[i]
|
||||||
|
|||||||
@ -209,20 +209,6 @@ var testCardsCleartext = []Card{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_Encrypt(t *testing.T) {
|
|
||||||
c := newClient(newManager(Config{}), "")
|
|
||||||
c.userKeyRing = testPrivateKeyRing
|
|
||||||
|
|
||||||
cardEncrypted, err := c.EncryptAndSignCards(testCardsCleartext)
|
|
||||||
r.Nil(t, err)
|
|
||||||
|
|
||||||
// Result is always different, so the best way is to test it by decrypting again.
|
|
||||||
// Another test for decrypting will help us to be sure it's working.
|
|
||||||
cardCleartext, err := c.DecryptAndVerifyCards(cardEncrypted)
|
|
||||||
r.Nil(t, err)
|
|
||||||
r.Equal(t, testCardsCleartext[0].Data, cardCleartext[0].Data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestClient_Decrypt(t *testing.T) {
|
func TestClient_Decrypt(t *testing.T) {
|
||||||
c := newClient(newManager(Config{}), "")
|
c := newClient(newManager(Config{}), "")
|
||||||
c.userKeyRing = testPrivateKeyRing
|
c.userKeyRing = testPrivateKeyRing
|
||||||
|
|||||||
@ -166,10 +166,6 @@ func (keys *PMKeys) UnlockAll(passphrase []byte, userKey *crypto.KeyRing) (kr *c
|
|||||||
// ErrNoKeyringAvailable represents an error caused by a keyring being nil or having no entities.
|
// ErrNoKeyringAvailable represents an error caused by a keyring being nil or having no entities.
|
||||||
var ErrNoKeyringAvailable = errors.New("no keyring available")
|
var ErrNoKeyringAvailable = errors.New("no keyring available")
|
||||||
|
|
||||||
func (c *client) encrypt(plain string, signer *crypto.KeyRing) (armored string, err error) {
|
|
||||||
return encrypt(c.userKeyRing, plain, signer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func encrypt(encrypter *crypto.KeyRing, plain string, signer *crypto.KeyRing) (armored string, err error) {
|
func encrypt(encrypter *crypto.KeyRing, plain string, signer *crypto.KeyRing) (armored string, err error) {
|
||||||
if encrypter == nil {
|
if encrypter == nil {
|
||||||
return "", ErrNoKeyringAvailable
|
return "", ErrNoKeyringAvailable
|
||||||
@ -209,18 +205,6 @@ func decrypt(decrypter *crypto.KeyRing, armored string) (plainBody []byte, err e
|
|||||||
return plainMessage.GetBinary(), nil
|
return plainMessage.GetBinary(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) sign(plain string) (armoredSignature string, err error) {
|
|
||||||
if c.userKeyRing == nil {
|
|
||||||
return "", ErrNoKeyringAvailable
|
|
||||||
}
|
|
||||||
plainMessage := crypto.NewPlainMessageFromString(plain)
|
|
||||||
pgpSignature, err := c.userKeyRing.SignDetached(plainMessage)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return pgpSignature.GetArmored()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *client) verify(plain, amroredSignature string) (err error) {
|
func (c *client) verify(plain, amroredSignature string) (err error) {
|
||||||
plainMessage := crypto.NewPlainMessageFromString(plain)
|
plainMessage := crypto.NewPlainMessageFromString(plain)
|
||||||
pgpSignature, err := crypto.NewPGPSignatureFromArmored(amroredSignature)
|
pgpSignature, err := crypto.NewPGPSignatureFromArmored(amroredSignature)
|
||||||
|
|||||||
Reference in New Issue
Block a user