diff --git a/openpgp/keys_test.go b/openpgp/keys_test.go index c1478771..57cd67be 100644 --- a/openpgp/keys_test.go +++ b/openpgp/keys_test.go @@ -982,24 +982,24 @@ func assertNotationPackets(t *testing.T, keys EntityList) { t.Fatalf("got %d Data Notation subpackets, expected %d", numSigs, numExpected) } - if notations[0].IsHumanReadable() != true { + if notations[0].HumanReadable != true { t.Fatalf("got false, expected true") } - if notations[0].GetName() != "test@example.com" { - t.Fatalf("got %s, expected test@example.com", notations[0].GetName()) + if notations[0].Name != "test@example.com" { + t.Fatalf("got %s, expected test@example.com", notations[0].Name) } - if notations[0].GetStringValue() != "2" { - t.Fatalf("got %s, expected 2", notations[0].GetName()) + if string(notations[0].Value) != "2" { + t.Fatalf("got %s, expected 2", string(notations[0].Value)) } - if notations[1].GetName() != "test@example.com" { - t.Fatalf("got %s, expected test@example.com", notations[0].GetName()) + if notations[1].Name != "test@example.com" { + t.Fatalf("got %s, expected test@example.com", notations[1].Name) } - if notations[1].GetStringValue() != "3" { - t.Fatalf("got %s, expected 3", notations[0].GetName()) + if string(notations[1].Value) != "3" { + t.Fatalf("got %s, expected 3", string(notations[1].Value)) } } diff --git a/openpgp/packet/notation.go b/openpgp/packet/notation.go index 967b00fb..5c215c2e 100644 --- a/openpgp/packet/notation.go +++ b/openpgp/packet/notation.go @@ -3,43 +3,27 @@ package packet // Notation type represents a Notation Data subpacket // see https://tools.ietf.org/html/rfc4880#section-5.2.3.16 type Notation struct { - flags []byte - name string - value []byte - critical bool + Name string + Value []byte + Critical bool + HumanReadable bool } -func (not *Notation) IsHumanReadable() (bool) { - return not.flags[0] & 0x80 == 0x80 -} - -func (not *Notation) GetName() (string) { - return not.name -} - -func (not *Notation) GetBinaryValue() ([]byte) { - return not.value -} - -func (not *Notation) GetStringValue() (string) { - return string(not.value) -} - -func (not *Notation) IsCritical() (bool) { - return not.critical -} +func (not *Notation) getData() []byte { + nameData := []byte(not.Name) + nameLen := len(nameData) + valueLen := len(not.Value) -func (not *Notation) getData() ([]byte) { - nameLen := len(not.name) - valueLen := len(not.value) - nameData := []byte(not.name) + data := make([]byte, 8 + nameLen + valueLen) + if not.HumanReadable { + data[0] = 0x80 + } - data := not.flags data[4] = byte(nameLen >> 8) data[5] = byte(nameLen) data[6] = byte(valueLen >> 8) data[7] = byte(valueLen) data = append(data, nameData...) - return append(data, not.value...) + return append(data, not.Value...) } diff --git a/openpgp/packet/signature.go b/openpgp/packet/signature.go index 225266b5..94689231 100644 --- a/openpgp/packet/signature.go +++ b/openpgp/packet/signature.go @@ -343,10 +343,10 @@ func parseSignatureSubpacket(sig *Signature, subpacket []byte, isHashed bool) (r } notation := Notation{ - flags: subpacket[0:4], - name: string(subpacket[8: (nameLength + 8)]), - value: subpacket[(nameLength + 8) : (valueLength + nameLength + 8)], - critical: isCritical, + HumanReadable: (subpacket[0] & 0x80) == 0x80, + Name: string(subpacket[8: (nameLength + 8)]), + Value: subpacket[(nameLength + 8) : (valueLength + nameLength + 8)], + Critical: isCritical, } sig.Notations = append(sig.Notations, notation) @@ -911,7 +911,7 @@ func (sig *Signature) buildSubpackets(issuer PublicKey) (subpackets []outputSubp outputSubpacket{ true, notationDataSubpacket, - notation.IsCritical(), + notation.Critical, notation.getData(), }) }