Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c8d77d9

Browse files
committedNov 24, 2023
docs(v2): Improve documentation in signatures for keys
1 parent e3b2b43 commit c8d77d9

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed
 

‎openpgp/packet/public_key.go

+8-21
Original file line numberDiff line numberDiff line change
@@ -874,13 +874,8 @@ func (pk *PublicKey) VerifyKeySignature(signed *PublicKey, sig *Signature) error
874874
return nil
875875
}
876876

877-
func keyRevocationHash(pk signingKey, hashFunc hash.Hash) (h hash.Hash, err error) {
878-
h = hashFunc
879-
880-
// RFC 4880, section 5.2.4
881-
err = pk.SerializeForHash(h)
882-
883-
return
877+
func keyRevocationHash(pk signingKey, hashFunc hash.Hash) (err error) {
878+
return pk.SerializeForHash(hashFunc)
884879
}
885880

886881
// VerifyRevocationSignature returns nil iff sig is a valid signature, made by this
@@ -890,11 +885,10 @@ func (pk *PublicKey) VerifyRevocationSignature(sig *Signature) (err error) {
890885
if err != nil {
891886
return err
892887
}
893-
h, err := keyRevocationHash(pk, preparedHash)
894-
if err != nil {
888+
if keyRevocationHash(pk, preparedHash); err != nil {
895889
return err
896890
}
897-
return pk.VerifySignature(h, sig)
891+
return pk.VerifySignature(preparedHash, sig)
898892
}
899893

900894
// VerifySubkeyRevocationSignature returns nil iff sig is a valid subkey revocation signature,
@@ -935,16 +929,9 @@ func userIdSignatureHash(id string, pk *PublicKey, h hash.Hash) (err error) {
935929
return nil
936930
}
937931

938-
// directSignatureHash returns a Hash of the message that needs to be signed
932+
// directKeySignatureHash returns a Hash of the message that needs to be signed.
939933
func directKeySignatureHash(pk *PublicKey, h hash.Hash) (err error) {
940-
// RFC 4880, section 5.2.4
941-
if err := pk.SerializeSignaturePrefix(h); err != nil {
942-
return err
943-
}
944-
if err := pk.serializeWithoutHeaders(h); err != nil {
945-
return err
946-
}
947-
return nil
934+
return pk.SerializeForHash(h)
948935
}
949936

950937
// VerifyUserIdSignature returns nil iff sig is a valid signature, made by this
@@ -960,8 +947,8 @@ func (pk *PublicKey) VerifyUserIdSignature(id string, pub *PublicKey, sig *Signa
960947
return pk.VerifySignature(h, sig)
961948
}
962949

963-
// VerifyUserIdSignature returns nil iff sig is a valid signature, made by this
964-
// public key
950+
// VerifyDirectKeySignature returns nil iff sig is a valid signature, made by this
951+
// public key.
965952
func (pk *PublicKey) VerifyDirectKeySignature(sig *Signature) (err error) {
966953
h, err := sig.PrepareVerify()
967954
if err != nil {

‎openpgp/v2/subkeys.go

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func (s *Subkey) Serialize(w io.Writer, includeSecrets bool) error {
7979
return nil
8080
}
8181

82+
// ReSign resigns the latest valid subkey binding signature with the given config.
8283
func (s *Subkey) ReSign(config *packet.Config) error {
8384
selectedSig, err := s.LatestValidBindingSignature(time.Time{})
8485
if err != nil {

‎openpgp/v2/user.go

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func readUser(e *Entity, packets *packet.Reader, pkt *packet.UserId) error {
7171
return nil
7272
}
7373

74+
// Serialize serializes the user id to the writer.
7475
func (i *Identity) Serialize(w io.Writer) error {
7576
if err := i.UserId.Serialize(w); err != nil {
7677
return err
@@ -135,6 +136,7 @@ func (i *Identity) Revoked(selfCertification *packet.Signature, date time.Time)
135136
return false
136137
}
137138

139+
// ReSign resigns the latest valid self-certification with the given config.
138140
func (i *Identity) ReSign(config *packet.Config) error {
139141
selectedSig, err := i.LatestValidSelfCertification(config.Now())
140142
if err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.