diff --git a/openpgp/keys.go b/openpgp/keys.go index 6eb88499..e41af5b0 100644 --- a/openpgp/keys.go +++ b/openpgp/keys.go @@ -32,7 +32,7 @@ type Entity struct { Subkeys []Subkey SelfSignature *packet.Signature // Direct-key self signature of the PrimaryKey (contains primary key properties in v6) Signatures []*packet.Signature // all (potentially unverified) self-signatures, revocations, and third-party signatures - UserAttribute []*UserAttribute + Attribute []*Attribute } // An Identity represents an identity claimed by an Entity and zero or more @@ -45,7 +45,7 @@ type Identity struct { Signatures []*packet.Signature // all (potentially unverified) self-signatures, revocations, and third-party signatures } -type UserAttribute struct { +type Attribute struct { UserAttribute *packet.UserAttribute SelfSignature *packet.Signature Revocations []*packet.Signature @@ -499,14 +499,14 @@ EachPacket: } switch pkt := p.(type) { - case *packet.UserAttribute: - if err := addUserAttribute(e, packets, pkt); err != nil { - return nil, err - } case *packet.UserId: if err := addUserID(e, packets, pkt); err != nil { return nil, err } + case *packet.UserAttribute: + if err := addUserAttribute(e, packets, pkt); err != nil { + return nil, err + } case *packet.Signature: if pkt.SigType == packet.SigTypeKeyRevocation { revocations = append(revocations, pkt) @@ -738,8 +738,7 @@ func (e *Entity) serializePrivate(w io.Writer, config *packet.Config, reSign boo } } } - - for _, uat := range e.UserAttribute { + for _, uat := range e.Attribute { if reSign { UserAttribute := uat.UserAttribute @@ -768,7 +767,6 @@ func (e *Entity) serializePrivate(w io.Writer, config *packet.Config, reSign boo } } } - for _, subkey := range e.Subkeys { err = subkey.PrivateKey.Serialize(w) if err != nil { @@ -833,7 +831,7 @@ func (e *Entity) Serialize(w io.Writer) error { } } - for _, uat := range e.UserAttribute { + for _, uat := range e.Attribute { err = uat.UserAttribute.Serialize(w) if err != nil { return err diff --git a/openpgp/read_write_test_data.go b/openpgp/read_write_test_data.go index 33aabf37..2f5947b5 100644 --- a/openpgp/read_write_test_data.go +++ b/openpgp/read_write_test_data.go @@ -457,7 +457,7 @@ byVJHvLO/XErtC+GNIJeMg== ` // Generated with the above private key -const pgpPhotoPublicOpenPGP2_2_34 = `-----BEGIN PGP PUBLIC KEY BLOCK----- +const pgpPhotoPublicGPG2_2_34 = `-----BEGIN PGP PUBLIC KEY BLOCK----- mQINBGMAOJkBEADnwgFNWjMe5/JkJ8ItTKsAzZpIbkpL3evG3PKMuP5zJDfLSA4I Nbfp6ztT13pwAJViFyjT6nDdo2IxCXeTY62CO7dy12sEqMPIuH3/ejh2PP7Y5918 @@ -827,7 +827,7 @@ zFHsmsYBDtjDzNPSv758Ze6dElm5Suuym2urEekmIr2WMa+fxnnEW+spW6z3zg== -----END PGP PUBLIC KEY BLOCK----- ` -const pgpPhotoPublicOpenPGP2_3_6 = `-----BEGIN PGP PUBLIC KEY BLOCK----- +const pgpPhotoPublicGPG2_3_6 = `-----BEGIN PGP PUBLIC KEY BLOCK----- mDMEYwMEERYJKwYBBAHaRw8BAQdAM+eSw80hM8YBvY1anfN6EMCDfe4rVdHYMyIU sgk6Y5G0FHRlc3QgPHRlc3RAdGVzdC5jb20+iJkEExYKAEEWIQQt/1rIQwoCvhlz diff --git a/openpgp/uat.go b/openpgp/uat.go index 3ae1778c..f2bc38a5 100644 --- a/openpgp/uat.go +++ b/openpgp/uat.go @@ -67,12 +67,12 @@ func (t *Entity) AddPhoto(jpegBytes []byte, config *packet.Config) error { if err != nil { return err } - userAttribute := &UserAttribute{ + userAttribute := &Attribute{ UserAttribute: uat, SelfSignature: selfSignature, Signatures: []*packet.Signature{selfSignature}, } - t.UserAttribute = append(t.UserAttribute, userAttribute) + t.Attribute = append(t.Attribute, userAttribute) return nil } @@ -80,9 +80,9 @@ func addUserAttribute(e *Entity, packets *packet.Reader, pkt *packet.UserAttribu // Make a new Identity object, that we might wind up throwing away. // We'll only add it if we get a valid self-signature over this // userID. - uat := new(UserAttribute) + uat := new(Attribute) uat.UserAttribute = pkt - e.UserAttribute = append(e.UserAttribute, uat) + e.Attribute = append(e.Attribute, uat) for { p, err := packets.Next() diff --git a/openpgp/uat_test.go b/openpgp/uat_test.go index 30239715..8aa381ed 100644 --- a/openpgp/uat_test.go +++ b/openpgp/uat_test.go @@ -1,7 +1,6 @@ // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. - package openpgp import ( @@ -9,13 +8,11 @@ import ( "encoding/base64" "testing" - "github.com/ProtonMail/go-crypto/openpgp/armor" "github.com/ProtonMail/go-crypto/openpgp/packet" ) -func TestUserattribute_CompatibleGunPG2_3_6(t *testing.T) { - - _, err := ReadArmoredKeyRing(bytes.NewBufferString((pgpPhotoPublicOpenPGP2_3_6))) +func TestUserattribute_CompatibleGPG2_3_6(t *testing.T) { + _, err := ReadArmoredKeyRing(bytes.NewBufferString(pgpPhotoPublicGPG2_3_6)) if err != nil { t.Fatal(err) } @@ -46,28 +43,13 @@ func TestAddPhoto(t *testing.T) { t.Fatal(err) } - if len(entity2.UserAttribute) != 1 { + if len(entity2.Attribute) != 1 { t.Fatal("data err, entity have no uat") } - imgBytes := entity2.UserAttribute[0].UserAttribute.ImageData() + imgBytes := entity2.Attribute[0].UserAttribute.ImageData() if !bytes.Equal(imgBytes[0], jpegBytes) { t.Fatal("image data not equal") } - if true { - - keybuf := bytes.NewBuffer(nil) - writer, err := armor.Encode(keybuf, PrivateKeyType, nil) - if err != nil { - return - } - err = entity.SerializePrivate(writer, nil) - if err != nil { - return - } - writer.Close() - gpgpstr := keybuf.String() - t.Logf("data: %v\n", gpgpstr) - } }