@@ -634,36 +634,17 @@ func (e *Entity) SignIdentity(identity string, signer *Entity, config *packet.Co
634
634
return nil
635
635
}
636
636
637
- // validRevocationReason reports whether the given revocation reason code is valid
638
- // as per RFC4880 section-5.2.3.23.
639
- func validRevocationReason (r uint8 ) bool {
640
- switch r {
641
- // Defined in RFC4880 section-5.2.3.23
642
- case 0 , 1 , 2 , 3 , 32 :
643
- return true
644
- default :
645
- // Private use (RFC4880 section-5.2.3.23)
646
- if 100 <= r && r <= 110 {
647
- return true
648
- }
649
- return false
650
- }
651
- }
652
-
653
637
// RevokeKey generates a key revocation signature (packet.SigTypeKeyRevocation) with the
654
638
// specified reason code and text (RFC4880 section-5.2.3.23).
655
639
// If config is nil, sensible defaults will be used.
656
- func (e * Entity ) RevokeKey (reason uint8 , reasonText string , config * packet.Config ) error {
657
- if ! validRevocationReason (reason ) {
658
- return errors .InvalidArgumentError ("invalid reason code" )
659
- }
660
-
640
+ func (e * Entity ) RevokeKey (reason packet.ReasonForRevocation , reasonText string , config * packet.Config ) error {
641
+ reasonCode := uint8 (reason )
661
642
revSig := & packet.Signature {
662
643
CreationTime : config .Now (),
663
644
SigType : packet .SigTypeKeyRevocation ,
664
645
PubKeyAlgo : packet .PubKeyAlgoRSA ,
665
646
Hash : config .Hash (),
666
- RevocationReason : & reason ,
647
+ RevocationReason : & reasonCode ,
667
648
RevocationReasonText : reasonText ,
668
649
IssuerKeyId : & e .PrimaryKey .KeyId ,
669
650
}
@@ -678,21 +659,18 @@ func (e *Entity) RevokeKey(reason uint8, reasonText string, config *packet.Confi
678
659
// RevokeSubkey generates a subkey revocation signature (packet.SigTypeSubkeyRevocation) for
679
660
// a subkey with the specified reason code and text (RFC4880 section-5.2.3.23).
680
661
// If config is nil, sensible defaults will be used.
681
- func (e * Entity ) RevokeSubkey (sk * Subkey , reason uint8 , reasonText string , config * packet.Config ) error {
682
- if ! validRevocationReason (reason ) {
683
- return errors .InvalidArgumentError ("invalid reason code" )
684
- }
685
-
662
+ func (e * Entity ) RevokeSubkey (sk * Subkey , reason packet.ReasonForRevocation , reasonText string , config * packet.Config ) error {
686
663
if err := e .PrimaryKey .VerifyKeySignature (sk .PublicKey , sk .Sig ); err != nil {
687
664
return errors .InvalidArgumentError ("given subkey is not associated with this key" )
688
665
}
689
666
667
+ reasonCode := uint8 (reason )
690
668
revSig := & packet.Signature {
691
669
CreationTime : config .Now (),
692
670
SigType : packet .SigTypeSubkeyRevocation ,
693
671
PubKeyAlgo : packet .PubKeyAlgoRSA ,
694
672
Hash : config .Hash (),
695
- RevocationReason : & reason ,
673
+ RevocationReason : & reasonCode ,
696
674
RevocationReasonText : reasonText ,
697
675
IssuerKeyId : & e .PrimaryKey .KeyId ,
698
676
}
0 commit comments