Skip to content

Commit

Permalink
Make notation structure fields exportable
Browse files Browse the repository at this point in the history
  • Loading branch information
wussler committed Dec 27, 2022
1 parent cc09ac3 commit d95af1d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 43 deletions.
18 changes: 9 additions & 9 deletions openpgp/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() != "[email protected]" {
t.Fatalf("got %s, expected [email protected]", notations[0].GetName())
if notations[0].Name != "[email protected]" {
t.Fatalf("got %s, expected [email protected]", 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() != "[email protected]" {
t.Fatalf("got %s, expected [email protected]", notations[0].GetName())
if notations[1].Name != "[email protected]" {
t.Fatalf("got %s, expected [email protected]", 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))
}
}

Expand Down
42 changes: 13 additions & 29 deletions openpgp/packet/notation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
10 changes: 5 additions & 5 deletions openpgp/packet/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -911,7 +911,7 @@ func (sig *Signature) buildSubpackets(issuer PublicKey) (subpackets []outputSubp
outputSubpacket{
true,
notationDataSubpacket,
notation.IsCritical(),
notation.Critical,
notation.getData(),
})
}
Expand Down

0 comments on commit d95af1d

Please sign in to comment.