Skip to content

Commit

Permalink
update uat
Browse files Browse the repository at this point in the history
  • Loading branch information
izouxv committed Sep 2, 2024
1 parent 7a01e13 commit 50c23b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 38 deletions.
18 changes: 8 additions & 10 deletions openpgp/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions openpgp/read_write_test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions openpgp/uat.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ 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
}

func addUserAttribute(e *Entity, packets *packet.Reader, pkt *packet.UserAttribute) error {
// 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()
Expand Down
26 changes: 4 additions & 22 deletions openpgp/uat_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
// 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 (
"bytes"
"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)
}
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 50c23b2

Please sign in to comment.