diff --git a/protonmail/adresses.go b/protonmail/adresses.go index 9d4e96c..66e785b 100644 --- a/protonmail/adresses.go +++ b/protonmail/adresses.go @@ -6,6 +6,23 @@ type ( AddressType int ) +const ( + AddressSendDisabled AddressSend = iota + AddressSendPrimary + AddressSendSecondary +) + +const ( + AddressDisabled AddressStatus = iota + AddressEnabled +) + +const ( + AddressOriginal AddressType = iota + AddressAlias + AddressCustom +) + type Address struct { ID string DomainID string @@ -17,5 +34,5 @@ type Address struct { DisplayName string Signature string // HTML HasKeys int - Keys []*Key + Keys []*PrivateKey } diff --git a/protonmail/keys.go b/protonmail/keys.go index 400c7d2..b5b6a3b 100644 --- a/protonmail/keys.go +++ b/protonmail/keys.go @@ -9,7 +9,7 @@ import ( "golang.org/x/crypto/openpgp" ) -type Key struct { +type PrivateKey struct { ID string Version int PublicKey string @@ -18,6 +18,17 @@ type Key struct { Activation interface{} // TODO } +func (priv *PrivateKey) Entity() (*openpgp.Entity, error) { + keyRing, err := openpgp.ReadArmoredKeyRing(strings.NewReader(priv.PrivateKey)) + if err != nil { + return nil, err + } + if len(keyRing) == 0 { + return nil, errors.New("private key is empty") + } + return keyRing[0], nil +} + type RecipientType int const ( diff --git a/protonmail/messages.go b/protonmail/messages.go index 9030d8a..32d9f58 100644 --- a/protonmail/messages.go +++ b/protonmail/messages.go @@ -196,6 +196,15 @@ type MessageKeyPacket struct { type MessagePackageType int +const ( + MessagePackageInternal MessagePackageType = 1 + MessagePackageEncryptedOutside = 2 + MessagePackageClear = 4 + MessagePackageInlinePGP = 8 + MessagePackagePGPMIME = 16 + MessagePackageMIME = 32 +) + type MessagePackage struct { Address string Type MessagePackageType @@ -210,10 +219,14 @@ type MessagePackage struct { type MessageOutgoing struct { ID string + // Only if there's a recipient without a public key ClearBody string - ExpirationTime int64 AttachmentKeys []*AttachmentKey - Packages []*MessagePackage + + // Only if message expires + ExpirationTime int // duration in seconds + + Packages []*MessagePackage } func (c *Client) SendMessage(msg *MessageOutgoing) (sent, parent *Message, err error) { diff --git a/protonmail/users.go b/protonmail/users.go index 091764d..dc35b4a 100644 --- a/protonmail/users.go +++ b/protonmail/users.go @@ -61,7 +61,7 @@ type User struct { VPN interface{} // TODO Delinquent int Addresses []*Address - Keys []*Key + Keys []*PrivateKey } func (c *Client) GetCurrentUser() (*User, error) {