From e3e4769d78eb2f51a625cd8810fe9177f8192699 Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Thu, 8 Jul 2021 13:01:23 +0200 Subject: [PATCH] Other: remove dead code --- internal/users/user.go | 20 -------------------- pkg/pmapi/contacts.go | 23 ----------------------- pkg/pmapi/contacts_test.go | 14 -------------- pkg/pmapi/keyring.go | 16 ---------------- 4 files changed, 73 deletions(-) diff --git a/internal/users/user.go b/internal/users/user.go index ce5e7aba..f1810e5d 100644 --- a/internal/users/user.go +++ b/internal/users/user.go @@ -279,26 +279,6 @@ func (u *User) GetStoreAddresses() []string { 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. func (u *User) GetAddresses() []string { u.lock.RLock() diff --git a/pkg/pmapi/contacts.go b/pkg/pmapi/contacts.go index 37583f40..7d27f595 100644 --- a/pkg/pmapi/contacts.go +++ b/pkg/pmapi/contacts.go @@ -64,29 +64,6 @@ var errVerificationFailed = errors.New("signature verification failed") // ================= 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) { for i := range cards { card := &cards[i] diff --git a/pkg/pmapi/contacts_test.go b/pkg/pmapi/contacts_test.go index ee7ef856..c707e4a8 100644 --- a/pkg/pmapi/contacts_test.go +++ b/pkg/pmapi/contacts_test.go @@ -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) { c := newClient(newManager(Config{}), "") c.userKeyRing = testPrivateKeyRing diff --git a/pkg/pmapi/keyring.go b/pkg/pmapi/keyring.go index 1b2b7796..513cf8ff 100644 --- a/pkg/pmapi/keyring.go +++ b/pkg/pmapi/keyring.go @@ -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. 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) { if encrypter == nil { return "", ErrNoKeyringAvailable @@ -209,18 +205,6 @@ func decrypt(decrypter *crypto.KeyRing, armored string) (plainBody []byte, err e 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) { plainMessage := crypto.NewPlainMessageFromString(plain) pgpSignature, err := crypto.NewPGPSignatureFromArmored(amroredSignature)