-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Notation data support in subpackets
- Loading branch information
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -944,6 +944,48 @@ func TestNewEntityPrivateSerialization(t *testing.T) { | |
} | ||
} | ||
|
||
func TestNotationPacket(t *testing.T) { | ||
keys, err := ReadArmoredKeyRing(bytes.NewBufferString(keyWithNotation)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(keys) != 1 { | ||
t.Errorf("Failed to accept key, %d", len(keys)) | ||
} | ||
|
||
identity := keys[0].Identities["Testt <test@exa>"] | ||
|
||
if numSigs, numExpected := len(identity.Signatures), 1; numSigs != numExpected { | ||
t.Fatalf("got %d signatures, expected %d", numSigs, numExpected) | ||
} | ||
|
||
notations := identity.Signatures[0].Notations | ||
if numSigs, numExpected := len(notations), 2; numSigs != numExpected { | ||
t.Fatalf("got %d Data Notation subpackets, expected %d", numSigs, numExpected) | ||
} | ||
|
||
if notations[0].IsHumanReadable() != 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].GetStringValue() != "2" { | ||
t.Fatalf("got %s, expected 2", notations[0].GetName()) | ||
} | ||
|
||
if notations[1].GetName() != "[email protected]" { | ||
t.Fatalf("got %s, expected [email protected]", notations[0].GetName()) | ||
} | ||
|
||
if notations[1].GetStringValue() != "3" { | ||
t.Fatalf("got %s, expected 3", notations[0].GetName()) | ||
} | ||
} | ||
|
||
func TestEntityPrivateSerialization(t *testing.T) { | ||
keys, err := ReadArmoredKeyRing(bytes.NewBufferString(armoredPrivateKeyBlock)) | ||
if err != nil { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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 | ||
} | ||
|
||
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) { | ||
nameLen := len(not.name) | ||
valueLen := len(not.value) | ||
nameData := []byte(not.name) | ||
|
||
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...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters