@@ -133,8 +133,8 @@ func (e *Entity) encryptionKey(now time.Time) (Key, bool) {
133133 // One more note: old DSA/ElGamal keys tend not to have the Flags subpacket,
134134 // so this sort of thing is pretty important for encrypting to older keys.
135135 //
136- if ((subkey .Sig .KeyFlags . Valid && subkey .Sig .KeyFlags . HasFlagEncryptCommunications () ) ||
137- (! subkey .Sig .KeyFlags . Valid && subkey .PublicKey .PubKeyAlgo == packet .PubKeyAlgoElGamal )) &&
136+ if ((subkey .Sig .FlagsValid && subkey .Sig .FlagEncryptCommunications ) ||
137+ (! subkey .Sig .FlagsValid && subkey .PublicKey .PubKeyAlgo == packet .PubKeyAlgoElGamal )) &&
138138 subkey .PublicKey .PubKeyAlgo .CanEncrypt () &&
139139 ! subkey .Sig .KeyExpired (now ) &&
140140 subkey .Revocation == nil &&
@@ -146,7 +146,7 @@ func (e *Entity) encryptionKey(now time.Time) (Key, bool) {
146146
147147 if candidateSubkey != - 1 {
148148 subkey := e .Subkeys [candidateSubkey ]
149- return Key {e , subkey .PublicKey , subkey .PrivateKey , subkey .Sig , subkey .Sig .KeyFlags }, true
149+ return Key {e , subkey .PublicKey , subkey .PrivateKey , subkey .Sig , subkey .Sig .GetKeyFlags () }, true
150150 }
151151
152152 // If we don't have any candidate subkeys for encryption and
@@ -157,10 +157,10 @@ func (e *Entity) encryptionKey(now time.Time) (Key, bool) {
157157 // NOTE(maxtaco) - see note above, how this policy is a little too open-ended
158158 // for my liking, but leave it for now.
159159 i := e .primaryIdentity ()
160- if (! i .SelfSignature .KeyFlags . Valid || i .SelfSignature .KeyFlags . HasFlagEncryptCommunications () ) &&
160+ if (! i .SelfSignature .FlagsValid || i .SelfSignature .FlagEncryptCommunications ) &&
161161 e .PrimaryKey .PubKeyAlgo .CanEncrypt () &&
162162 ! i .SelfSignature .KeyExpired (now ) {
163- return Key {e , e .PrimaryKey , e .PrivateKey , i .SelfSignature , i .SelfSignature .KeyFlags }, true
163+ return Key {e , e .PrimaryKey , e .PrivateKey , i .SelfSignature , i .SelfSignature .GetKeyFlags () }, true
164164 }
165165
166166 // This Entity appears to be signing only.
@@ -173,7 +173,7 @@ func (e *Entity) signingKey(now time.Time) (Key, bool) {
173173 candidateSubkey := - 1
174174
175175 for i , subkey := range e .Subkeys {
176- if (! subkey .Sig .KeyFlags . Valid || subkey .Sig .KeyFlags . HasFlagSign () ) &&
176+ if (! subkey .Sig .FlagsValid || subkey .Sig .FlagSign ) &&
177177 subkey .PrivateKey .PrivateKey != nil &&
178178 subkey .PublicKey .PubKeyAlgo .CanSign () &&
179179 subkey .Revocation == nil &&
@@ -185,17 +185,17 @@ func (e *Entity) signingKey(now time.Time) (Key, bool) {
185185
186186 if candidateSubkey != - 1 {
187187 subkey := e .Subkeys [candidateSubkey ]
188- return Key {e , subkey .PublicKey , subkey .PrivateKey , subkey .Sig , subkey .Sig .KeyFlags }, true
188+ return Key {e , subkey .PublicKey , subkey .PrivateKey , subkey .Sig , subkey .Sig .GetKeyFlags () }, true
189189 }
190190
191191 // If we have no candidate subkey then we assume that it's ok to sign
192192 // with the primary key.
193193 i := e .primaryIdentity ()
194- if (! i .SelfSignature .KeyFlags . Valid || i .SelfSignature .KeyFlags . HasFlagSign () ) &&
194+ if (! i .SelfSignature .FlagsValid || i .SelfSignature .FlagSign ) &&
195195 e .PrimaryKey .PubKeyAlgo .CanSign () &&
196196 ! i .SelfSignature .KeyExpired (now ) &&
197197 e .PrivateKey .PrivateKey != nil {
198- return Key {e , e .PrimaryKey , e .PrivateKey , i .SelfSignature , i .SelfSignature .KeyFlags }, true
198+ return Key {e , e .PrimaryKey , e .PrivateKey , i .SelfSignature , i .SelfSignature .GetKeyFlags () }, true
199199 }
200200
201201 return Key {}, false
@@ -227,13 +227,13 @@ func (el EntityList) KeysById(id uint64, fp []byte) (keys []Key) {
227227 selfSig = ident .SelfSignature
228228 } else if ident .SelfSignature .IsPrimaryId != nil && * ident .SelfSignature .IsPrimaryId {
229229 selfSig = ident .SelfSignature
230- break ;
230+ break
231231 }
232232 }
233233
234234 var keyFlags packet.KeyFlagBits
235235 for _ , ident := range e .Identities {
236- keyFlags .Merge (ident .SelfSignature .KeyFlags )
236+ keyFlags .Merge (ident .SelfSignature .GetKeyFlags () )
237237 }
238238
239239 keys = append (keys , Key {e , e .PrimaryKey , e .PrivateKey , selfSig , keyFlags })
@@ -249,7 +249,7 @@ func (el EntityList) KeysById(id uint64, fp []byte) (keys []Key) {
249249 sig = subKey .Sig
250250 }
251251
252- keys = append (keys , Key {e , subKey .PublicKey , subKey .PrivateKey , sig , sig .KeyFlags })
252+ keys = append (keys , Key {e , subKey .PublicKey , subKey .PrivateKey , sig , sig .GetKeyFlags () })
253253 }
254254 }
255255 }
@@ -314,8 +314,8 @@ func (el EntityList) KeysByIdUsage(id uint64, fp []byte, requiredUsage byte) (ke
314314func (el EntityList ) DecryptionKeys () (keys []Key ) {
315315 for _ , e := range el {
316316 for _ , subKey := range e .Subkeys {
317- if subKey .PrivateKey != nil && subKey .PrivateKey .PrivateKey != nil && (! subKey .Sig .KeyFlags . Valid || subKey .Sig .KeyFlags . HasFlagEncryptStorage () || subKey .Sig .KeyFlags . HasFlagEncryptCommunications () ) {
318- keys = append (keys , Key {e , subKey .PublicKey , subKey .PrivateKey , subKey .Sig , subKey .Sig .KeyFlags })
317+ if subKey .PrivateKey != nil && subKey .PrivateKey .PrivateKey != nil && (! subKey .Sig .FlagsValid || subKey .Sig .FlagEncryptStorage || subKey .Sig .FlagEncryptCommunications ) {
318+ keys = append (keys , Key {e , subKey .PublicKey , subKey .PrivateKey , subKey .Sig , subKey .Sig .GetKeyFlags () })
319319 }
320320 }
321321 }
@@ -491,7 +491,7 @@ EachPacket:
491491 if current != nil &&
492492 (current .SelfSignature == nil ||
493493 (! pkt .CreationTime .Before (current .SelfSignature .CreationTime ) &&
494- (pkt .KeyFlags . Valid || ! current .SelfSignature .KeyFlags . Valid ))) &&
494+ (pkt .FlagsValid || ! current .SelfSignature .FlagsValid ))) &&
495495 (pkt .SigType == packet .SigTypePositiveCert || pkt .SigType == packet .SigTypeGenericCert ) &&
496496 pkt .IssuerKeyId != nil &&
497497 * pkt .IssuerKeyId == e .PrimaryKey .KeyId {
@@ -698,7 +698,9 @@ func NewEntity(name, comment, email string, config *packet.Config) (*Entity, err
698698 PubKeyAlgo : packet .PubKeyAlgoRSA ,
699699 Hash : config .Hash (),
700700 IsPrimaryId : & isPrimaryId ,
701- KeyFlags : packet.KeyFlagBits {true , packet .KeyFlagEncryptStorage | packet .KeyFlagEncryptCommunications },
701+ FlagsValid : true ,
702+ FlagSign : true ,
703+ FlagCertify : true ,
702704 IssuerKeyId : & e .PrimaryKey .KeyId ,
703705 },
704706 }
@@ -708,12 +710,14 @@ func NewEntity(name, comment, email string, config *packet.Config) (*Entity, err
708710 PublicKey : packet .NewRSAPublicKey (currentTime , & encryptingPriv .PublicKey ),
709711 PrivateKey : packet .NewRSAPrivateKey (currentTime , encryptingPriv ),
710712 Sig : & packet.Signature {
711- CreationTime : currentTime ,
712- SigType : packet .SigTypeSubkeyBinding ,
713- PubKeyAlgo : packet .PubKeyAlgoRSA ,
714- Hash : config .Hash (),
715- KeyFlags : packet.KeyFlagBits {true , packet .KeyFlagEncryptStorage | packet .KeyFlagEncryptCommunications },
716- IssuerKeyId : & e .PrimaryKey .KeyId ,
713+ CreationTime : currentTime ,
714+ SigType : packet .SigTypeSubkeyBinding ,
715+ PubKeyAlgo : packet .PubKeyAlgoRSA ,
716+ Hash : config .Hash (),
717+ FlagsValid : true ,
718+ FlagEncryptStorage : true ,
719+ FlagEncryptCommunications : true ,
720+ IssuerKeyId : & e .PrimaryKey .KeyId ,
717721 },
718722 }
719723 e .Subkeys [0 ].PublicKey .IsSubkey = true
0 commit comments