From 467922090a57fbe898b155f883371e682dc59cc9 Mon Sep 17 00:00:00 2001 From: Alex Richards Date: Sat, 20 Jul 2024 22:53:54 +1200 Subject: [PATCH] tagged cbor type --- authentication.go | 27 +++++++++------ cbor.go | 69 ++++++++++++++++++++++++++++++++++---- cbor_test.go | 18 ++++++---- device_engagement.go | 18 +++++++--- device_engagement_test.go | 35 ++++++++++++++----- device_request.go | 12 ++++--- device_response.go | 27 ++++++++++----- iso_18013_5_test.go | 27 +++++++++------ session_data.go | 17 ++++++++-- session_data_test.go | 24 +++++++++---- session_transcript.go | 10 +++--- session_transcript_test.go | 23 ++++++++++--- 12 files changed, 225 insertions(+), 82 deletions(-) diff --git a/authentication.go b/authentication.go index 2147044..0a097ad 100644 --- a/authentication.go +++ b/authentication.go @@ -7,9 +7,6 @@ import ( "github.com/veraison/go-cose" ) -type EDeviceKeyBytes TaggedEncodedCBOR -type EReaderKeyBytes TaggedEncodedCBOR - type ReaderAuth cose.UntaggedSign1Message func (ra *ReaderAuth) MarshalCBOR() ([]byte, error) { @@ -24,7 +21,7 @@ type ReaderAuthentication struct { _ struct{} `cbor:",toarray"` ReaderAuthentication string SessionTranscript SessionTranscript - ItemsRequestBytes ItemsRequestBytes + ItemsRequestBytes TaggedEncodedCBOR } type IssuerAuth cose.UntaggedSign1Message @@ -41,19 +38,29 @@ type DeviceAuth struct { // DeviceMAC DeviceMAC } -func (ia *IssuerAuth) MobileSecurityObjectBytes() MobileSecurityObjectBytes { - return ia.Payload +func (ia *IssuerAuth) MobileSecurityObjectBytes() (*TaggedEncodedCBOR, error) { + mobileSecurityObjectBytes := new(TaggedEncodedCBOR) + err := cbor.Unmarshal(ia.Payload, mobileSecurityObjectBytes) + if err != nil { + return nil, err + } + + return mobileSecurityObjectBytes, nil } func (ia *IssuerAuth) MobileSecurityObject() (*MobileSecurityObject, error) { - var mobileSecurityObjectBytes MobileSecurityObjectBytes - err := cbor.Unmarshal(ia.Payload, &mobileSecurityObjectBytes) + mobileSecurityObjectBytes, err := ia.MobileSecurityObjectBytes() + if err != nil { + return nil, err + } + + mobileSecurityObjectBytesUntagged, err := mobileSecurityObjectBytes.UntaggedValue() if err != nil { return nil, err } mobileSecurityObject := new(MobileSecurityObject) - err = cbor.Unmarshal(mobileSecurityObjectBytes, mobileSecurityObject) + err = cbor.Unmarshal(mobileSecurityObjectBytesUntagged, mobileSecurityObject) if err != nil { return nil, err } @@ -72,8 +79,6 @@ func (ds *DeviceSignature) UnmarshalCBOR(data []byte) error { // type DeviceMAC cose.Mac0Message -type MobileSecurityObjectBytes TaggedEncodedCBOR - type MobileSecurityObject struct { Version string `cbor:"version"` DigestAlgorithm DigestAlgorithm `cbor:"digestAlgorithm"` diff --git a/cbor.go b/cbor.go index cba0bf5..cf39f7c 100644 --- a/cbor.go +++ b/cbor.go @@ -1,6 +1,7 @@ package mdoc import ( + "errors" "reflect" "github.com/fxamacker/cbor/v2" @@ -8,8 +9,11 @@ import ( const TagEncodedCBOR = 24 -type TaggedEncodedCBOR []byte -type taggedEncodedCBOR []byte +type bstr []byte +type TaggedEncodedCBOR struct { + taggedValue bstr + untaggedValue bstr +} var ( encodeModeTaggedEncodedCBOR cbor.EncMode @@ -20,7 +24,7 @@ func init() { ts := cbor.NewTagSet() ts.Add( cbor.TagOptions{DecTag: cbor.DecTagRequired, EncTag: cbor.EncTagRequired}, - reflect.TypeOf(taggedEncodedCBOR{}), + reflect.TypeOf(bstr{}), TagEncodedCBOR, ) @@ -37,10 +41,61 @@ func init() { } } -func (ec *TaggedEncodedCBOR) MarshalCBOR() ([]byte, error) { - return encodeModeTaggedEncodedCBOR.Marshal((*taggedEncodedCBOR)(ec)) +func (tec *TaggedEncodedCBOR) TaggedValue() ([]byte, error) { + if tec.taggedValue != nil { + return tec.taggedValue, nil + } + + if tec.untaggedValue != nil { + return encodeModeTaggedEncodedCBOR.Marshal(tec.untaggedValue) + } + + return nil, errors.New("TODO - TaggedValue - empty") } -func (ec *TaggedEncodedCBOR) UnmarshalCBOR(data []byte) error { - return decodeModeTaggedEncodedCBOR.Unmarshal(data, (*taggedEncodedCBOR)(ec)) +func (tec *TaggedEncodedCBOR) UntaggedValue() ([]byte, error) { + if tec.untaggedValue != nil { + return tec.untaggedValue, nil + } + + if tec.taggedValue != nil { + var untaggedValue []byte + if err := decodeModeTaggedEncodedCBOR.Unmarshal(tec.taggedValue, untaggedValue); err != nil { + return nil, err + } + + return untaggedValue, nil + } + + return nil, errors.New("TODO - UntaggedValue - empty") +} + +func (tec *TaggedEncodedCBOR) MarshalCBOR() ([]byte, error) { + return tec.TaggedValue() +} + +func (tec *TaggedEncodedCBOR) UnmarshalCBOR(taggedValue []byte) error { + var untaggedValue []byte + err := decodeModeTaggedEncodedCBOR.Unmarshal(taggedValue, &untaggedValue) + if err != nil { + return err + } + + tec.taggedValue = taggedValue + tec.untaggedValue = untaggedValue + return nil +} + +func NewTaggedEncodedCBOR(untaggedValue []byte) (*TaggedEncodedCBOR, error) { + taggedEncodedCBOR := TaggedEncodedCBOR{ + untaggedValue: untaggedValue, + } + + var err error + taggedEncodedCBOR.taggedValue, err = taggedEncodedCBOR.TaggedValue() + if err != nil { + return nil, err + } + + return &taggedEncodedCBOR, nil } diff --git a/cbor_test.go b/cbor_test.go index d968dfb..accf236 100644 --- a/cbor_test.go +++ b/cbor_test.go @@ -25,26 +25,30 @@ func TestEncodedCBORTagged(t *testing.T) { t.Fatal(err) } - errUntagged := cbor.Unmarshal(testStructBytes, TaggedEncodedCBOR{}) + errUntagged := cbor.Unmarshal(testStructBytes, &TaggedEncodedCBOR{}) if errUntagged == nil { t.Fatal() } - testStructBytesTagged, err := cbor.Marshal((TaggedEncodedCBOR)(testStructBytes)) + taggedEncodedCBOR, err := NewTaggedEncodedCBOR(testStructBytes) if err != nil { t.Fatal(err) } - if bytes.Equal(testStructBytesTagged[0:1], []byte{0xd8, TagEncodedCBOR}) { + + testStructBytesTagged, err := cbor.Marshal(taggedEncodedCBOR) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(testStructBytesTagged[0:2], []byte{0xd8, TagEncodedCBOR}) { t.Fatal(hex.EncodeToString(testStructBytesTagged)) } - testStructBytesUntagged := make([]byte, 0) - err = cbor.Unmarshal(testStructBytesTagged, (*TaggedEncodedCBOR)(&testStructBytesUntagged)) - if err != nil { + var taggedEncodedCBORUnmarshalled TaggedEncodedCBOR + if err = cbor.Unmarshal(testStructBytesTagged, &taggedEncodedCBORUnmarshalled); err != nil { t.Fatal(err) } - if diff := cmp.Diff(testStructBytes, testStructBytesUntagged); diff != "" { + if diff := cmp.Diff(testStructBytes, []byte(taggedEncodedCBORUnmarshalled.untaggedValue)); diff != "" { t.Fatal(diff) } } diff --git a/device_engagement.go b/device_engagement.go index fddd867..cc74f05 100644 --- a/device_engagement.go +++ b/device_engagement.go @@ -8,7 +8,6 @@ import ( "github.com/veraison/go-cose" ) -type DeviceEngagementBytes TaggedEncodedCBOR type DeviceEngagement struct { Version string `cbor:"0,keyasint"` Security Security `cbor:"1,keyasint"` @@ -31,10 +30,16 @@ func NewDeviceEngagement(eDeviceKey *cose.Key) (*DeviceEngagement, error) { } func (de *DeviceEngagement) EDeviceKey() (*cose.Key, error) { + eDeviceKeyBytesUntagged, err := de.Security.EDeviceKeyBytes.UntaggedValue() + if err != nil { + return nil, err + } + eDeviceKey := new(cose.Key) - if err := cbor.Unmarshal(de.Security.EDeviceKeyBytes, eDeviceKey); err != nil { + if err := cbor.Unmarshal(eDeviceKeyBytesUntagged, eDeviceKey); err != nil { return nil, err } + return eDeviceKey, nil } @@ -45,14 +50,19 @@ type Security struct { } func newSecurity(eDeviceKey *cose.Key) (*Security, error) { - eDeviceKeyBytes, err := cbor.Marshal(eDeviceKey) + eDeviceKeyBytesUntagged, err := cbor.Marshal(eDeviceKey) + if err != nil { + return nil, err + } + + eDeviceKeyBytes, err := NewTaggedEncodedCBOR(eDeviceKeyBytesUntagged) if err != nil { return nil, err } return &Security{ CipherSuiteIdentifier: 1, - EDeviceKeyBytes: eDeviceKeyBytes, + EDeviceKeyBytes: *eDeviceKeyBytes, }, nil } diff --git a/device_engagement_test.go b/device_engagement_test.go index 9662a92..d0b92f9 100644 --- a/device_engagement_test.go +++ b/device_engagement_test.go @@ -1,6 +1,7 @@ package mdoc import ( + "reflect" "testing" "github.com/fxamacker/cbor/v2" @@ -20,12 +21,18 @@ func TestNewDeviceEngagement(t *testing.T) { } func TestDeviceEngagementCBORRoundTrip(t *testing.T) { + eDeviceKeyBytes, err := NewTaggedEncodedCBOR([]byte{1, 2, 3, 4}) + if err != nil { + t.Fatal(err) + } + peripheralServerUUID := uuid.New() + deviceEngagement := &DeviceEngagement{ Version: "1.0", Security: Security{ CipherSuiteIdentifier: 1, - EDeviceKeyBytes: []byte{1, 2, 3, 4}, + EDeviceKeyBytes: *eDeviceKeyBytes, }, DeviceRetrievalMethods: []DeviceRetrievalMethod{ { @@ -52,17 +59,28 @@ func TestDeviceEngagementCBORRoundTrip(t *testing.T) { t.Fatal(err) } - if diff := cmp.Diff(deviceEngagement, deviceEngagementUnmarshalled); diff != "" { + if diff := cmp.Diff( + deviceEngagement, + deviceEngagementUnmarshalled, + cmp.FilterPath(func(p cmp.Path) bool { + return p.Last().Type() == reflect.TypeOf(TaggedEncodedCBOR{}) + }, cmp.Ignore()), + ); diff != "" { t.Fatal(diff) } } func TestDeviceEngagementUnknownMethod(t *testing.T) { - deviceEngagement := &DeviceEngagement{ + eDeviceKeyBytes, err := NewTaggedEncodedCBOR([]byte{1, 2, 3, 4}) + if err != nil { + t.Fatal(err) + } + + deviceEngagement := DeviceEngagement{ Version: "1.0", Security: Security{ CipherSuiteIdentifier: 1, - EDeviceKeyBytes: []byte{1, 2, 3, 4}, + EDeviceKeyBytes: *eDeviceKeyBytes, }, DeviceRetrievalMethods: []DeviceRetrievalMethod{ { @@ -72,15 +90,14 @@ func TestDeviceEngagementUnknownMethod(t *testing.T) { }, } - deviceEngagementBytes, err := cbor.Marshal(deviceEngagement) + deviceEngagementBytes, err := cbor.Marshal(&deviceEngagement) if err != nil { t.Fatal(err) } - deviceEngagementUnmarshalled := new(DeviceEngagement) - err = cbor.Unmarshal(deviceEngagementBytes, deviceEngagementUnmarshalled) - if err == nil { - t.Fatal() + var deviceEngagementUnmarshalled DeviceEngagement + if err = cbor.Unmarshal(deviceEngagementBytes, &deviceEngagementUnmarshalled); err == nil { + t.Fatal("expected error") } errUnreccognisedReterevalMethod := err.(*ErrorUnreccognisedReterevalMethod) diff --git a/device_request.go b/device_request.go index 698ee82..8a77e94 100644 --- a/device_request.go +++ b/device_request.go @@ -15,20 +15,24 @@ func NewDeviceRequest(docRequests []DocRequest) *DeviceRequest { } type DocRequest struct { - ItemsRequestBytes ItemsRequestBytes `cbor:"itemsRequest"` + ItemsRequestBytes TaggedEncodedCBOR `cbor:"itemsRequest"` ReaderAuth ReaderAuth `cbor:"readerAuth"` } func (dr *DocRequest) ItemsRequest() (*ItemsRequest, error) { - itemsRequest := new(ItemsRequest) - err := cbor.Unmarshal(dr.ItemsRequestBytes, itemsRequest) + itemsRequestBytesUntagged, err := dr.ItemsRequestBytes.UntaggedValue() if err != nil { return nil, err } + + itemsRequest := new(ItemsRequest) + if err := cbor.Unmarshal(itemsRequestBytesUntagged, itemsRequest); err != nil { + return nil, err + } + return itemsRequest, nil } -type ItemsRequestBytes TaggedEncodedCBOR type ItemsRequest struct { DocType DocType `cbor:"docType"` NameSpaces NameSpaces `cbor:"nameSpaces"` diff --git a/device_response.go b/device_response.go index 968b05d..64c48e1 100644 --- a/device_response.go +++ b/device_response.go @@ -48,7 +48,7 @@ type IssuerSigned struct { } type IssuerNameSpaces map[NameSpace]IssuerSignedItemBytess -type IssuerSignedItemBytess []IssuerSignedItemBytes +type IssuerSignedItemBytess []TaggedEncodedCBOR type IssuerSignedItems map[NameSpace][]IssuerSignedItem func (ins IssuerNameSpaces) IssuerSignedItems() (IssuerSignedItems, error) { @@ -57,13 +57,19 @@ func (ins IssuerNameSpaces) IssuerSignedItems() (IssuerSignedItems, error) { if issuerSignedItemBytess == nil { return nil, errors.New("TODO") } + issuerSignedItems := make([]IssuerSignedItem, len(issuerSignedItemBytess)) for i, issuerSignedItemBytes := range issuerSignedItemBytess { - var issuerSignedItem IssuerSignedItem - err := cbor.Unmarshal(issuerSignedItemBytes, &issuerSignedItem) + issuerSignedItemBytesUntagged, err := issuerSignedItemBytes.UntaggedValue() if err != nil { return nil, err } + + var issuerSignedItem IssuerSignedItem + if err = cbor.Unmarshal(issuerSignedItemBytesUntagged, &issuerSignedItem); err != nil { + return nil, err + } + issuerSignedItems[i] = issuerSignedItem } issuerSignedItemss[nameSpace] = issuerSignedItems @@ -71,7 +77,6 @@ func (ins IssuerNameSpaces) IssuerSignedItems() (IssuerSignedItems, error) { return issuerSignedItemss, nil } -type IssuerSignedItemBytes TaggedEncodedCBOR type IssuerSignedItem struct { DigestID uint `cbor:"digestID"` Random []byte `cbor:"random"` @@ -80,20 +85,24 @@ type IssuerSignedItem struct { } type DeviceSigned struct { - NameSpacesBytes DeviceNameSpacesBytes `cbor:"nameSpaces"` - DeviceAuth DeviceAuth `cbor:"deviceAuth"` + NameSpacesBytes TaggedEncodedCBOR `cbor:"nameSpaces"` + DeviceAuth DeviceAuth `cbor:"deviceAuth"` } func (ds *DeviceSigned) NameSpaces() (DeviceNameSpaces, error) { - deviceNameSpaces := make(DeviceNameSpaces) - err := cbor.Unmarshal(ds.NameSpacesBytes, &deviceNameSpaces) + nameSpacesBytesUntagged, err := ds.NameSpacesBytes.UntaggedValue() if err != nil { return nil, err } + + deviceNameSpaces := make(DeviceNameSpaces) + if err = cbor.Unmarshal(nameSpacesBytesUntagged, &deviceNameSpaces); err != nil { + return nil, err + } + return deviceNameSpaces, nil } -type DeviceNameSpacesBytes TaggedEncodedCBOR type DeviceNameSpaces map[NameSpace]DeviceSignedItems type DeviceSignedItems map[DataElementIdentifier]DataElementValue diff --git a/iso_18013_5_test.go b/iso_18013_5_test.go index 3519fd7..0d2af3c 100644 --- a/iso_18013_5_test.go +++ b/iso_18013_5_test.go @@ -313,8 +313,8 @@ func TestDecodeDeviceEngagement(t *testing.T) { t.Fatal(err) } - deviceEngagement := new(DeviceEngagement) - if err = cbor.Unmarshal(deviceEngagementBytes, deviceEngagement); err != nil { + var deviceEngagement DeviceEngagement + if err = cbor.Unmarshal(deviceEngagementBytes, &deviceEngagement); err != nil { t.Fatal(err) } @@ -343,8 +343,8 @@ func TestDecodeSessionEstablishment(t *testing.T) { t.Fatal(err) } - sessionEstablishment := new(SessionEstablishment) - if err = cbor.Unmarshal(sessionEstablishmentBytes, sessionEstablishment); err != nil { + var sessionEstablishment SessionEstablishment + if err = cbor.Unmarshal(sessionEstablishmentBytes, &sessionEstablishment); err != nil { t.Fatal(err) } @@ -373,8 +373,8 @@ func TestDecodeSessionData(t *testing.T) { t.Fatal(err) } - sessionData := new(SessionData) - if err = cbor.Unmarshal(sessionDataBytes, sessionData); err != nil { + var sessionData SessionData + if err = cbor.Unmarshal(sessionDataBytes, &sessionData); err != nil { t.Fatal(err) } } @@ -425,8 +425,8 @@ func TestDecodeDeviceRequest(t *testing.T) { t.Fatal(err) } - deviceRequest := new(DeviceRequest) - err = cbor.Unmarshal(deviceRequestBytes, deviceRequest) + var deviceRequest DeviceRequest + err = cbor.Unmarshal(deviceRequestBytes, &deviceRequest) if err != nil { t.Fatal(err) } @@ -445,8 +445,8 @@ func TestDecodeDeviceResponse(t *testing.T) { t.Fatal(err) } - deviceResponse := new(DeviceResponse) - err = cbor.Unmarshal(deviceResponseBytes, deviceResponse) + var deviceResponse DeviceResponse + err = cbor.Unmarshal(deviceResponseBytes, &deviceResponse) if err != nil { t.Fatal(err) } @@ -481,8 +481,13 @@ func TestDecodeSessionTranscript(t *testing.T) { t.Fatal(err) } + sessionTranscriptBytesUntagged, err := sessionTranscriptBytes.UntaggedValue() + if err != nil { + t.Fatal(err) + } + var sessionTranscript SessionTranscript - err = cbor.Unmarshal(sessionTranscriptBytes, &sessionTranscript) + err = cbor.Unmarshal(sessionTranscriptBytesUntagged, &sessionTranscript) if err != nil { t.Fatal(err) } diff --git a/session_data.go b/session_data.go index 91dc784..ce18608 100644 --- a/session_data.go +++ b/session_data.go @@ -17,13 +17,18 @@ type SessionEstablishment struct { } func NewSessionEstablishment(eReaderKey *cose.Key, data []byte) (*SessionEstablishment, error) { - eReaderKeyBytes, err := cbor.Marshal(eReaderKey) + eReaderKeyBytesUntagged, err := cbor.Marshal(eReaderKey) + if err != nil { + return nil, err + } + + eReaderKeyBytes, err := NewTaggedEncodedCBOR(eReaderKeyBytesUntagged) if err != nil { return nil, err } return &SessionEstablishment{ - EReaderKeyBytes: eReaderKeyBytes, + EReaderKeyBytes: *eReaderKeyBytes, Data: data, }, nil } @@ -34,9 +39,15 @@ type SessionData struct { } func (se *SessionEstablishment) EReaderKey() (*cose.Key, error) { + eReaderKeyBytesUntagged, err := se.EReaderKeyBytes.UntaggedValue() + if err != nil { + return nil, err + } + eReaderKey := new(cose.Key) - if err := cbor.Unmarshal(se.EReaderKeyBytes, eReaderKey); err != nil { + if err := cbor.Unmarshal(eReaderKeyBytesUntagged, eReaderKey); err != nil { return nil, err } + return eReaderKey, nil } diff --git a/session_data_test.go b/session_data_test.go index 48a3c4e..b285573 100644 --- a/session_data_test.go +++ b/session_data_test.go @@ -1,6 +1,7 @@ package mdoc import ( + "reflect" "testing" "github.com/fxamacker/cbor/v2" @@ -22,22 +23,33 @@ func TestNewSessionEstablishment(t *testing.T) { } func TestSessionEstablishmentCBORRoundTrip(t *testing.T) { - sessionEstablishment := &SessionEstablishment{ - EReaderKeyBytes: []byte{1, 2, 3, 4}, + eReaderKeyBytes, err := NewTaggedEncodedCBOR([]byte{1, 2, 3, 4}) + if err != nil { + t.Fatal(err) + } + + sessionEstablishment := SessionEstablishment{ + EReaderKeyBytes: *eReaderKeyBytes, Data: []byte{5, 6, 7, 8}, } - sessionEstablishmentBytes, err := cbor.Marshal(sessionEstablishment) + sessionEstablishmentBytes, err := cbor.Marshal(&sessionEstablishment) if err != nil { t.Fatal(err) } - sessionEstablishmentUnmarshalled := new(SessionEstablishment) - if err = cbor.Unmarshal(sessionEstablishmentBytes, sessionEstablishmentUnmarshalled); err != nil { + var sessionEstablishmentUnmarshalled SessionEstablishment + if err = cbor.Unmarshal(sessionEstablishmentBytes, &sessionEstablishmentUnmarshalled); err != nil { t.Fatal(err) } - if diff := cmp.Diff(sessionEstablishment, sessionEstablishmentUnmarshalled); diff != "" { + if diff := cmp.Diff( + sessionEstablishment, + sessionEstablishmentUnmarshalled, + cmp.FilterPath(func(p cmp.Path) bool { + return p.Last().Type() == reflect.TypeOf(TaggedEncodedCBOR{}) + }, cmp.Ignore()), + ); diff != "" { t.Fatal(diff) } } diff --git a/session_transcript.go b/session_transcript.go index f8261e3..243532b 100644 --- a/session_transcript.go +++ b/session_transcript.go @@ -7,18 +7,16 @@ import ( "github.com/fxamacker/cbor/v2" ) -type SessionTranscriptBytes TaggedEncodedCBOR - type SessionTranscript struct { - DeviceEngagementBytes DeviceEngagementBytes - EReaderKeyBytes EReaderKeyBytes + DeviceEngagementBytes TaggedEncodedCBOR + EReaderKeyBytes TaggedEncodedCBOR Handover Handover } type intermediateSessionTranscript struct { _ struct{} `cbor:",toarray"` - DeviceEngagementBytes DeviceEngagementBytes - EReaderKeyBytes EReaderKeyBytes + DeviceEngagementBytes TaggedEncodedCBOR + EReaderKeyBytes TaggedEncodedCBOR Handover cbor.RawMessage } diff --git a/session_transcript_test.go b/session_transcript_test.go index 85a13ae..df2f6d6 100644 --- a/session_transcript_test.go +++ b/session_transcript_test.go @@ -1,6 +1,7 @@ package mdoc import ( + "reflect" "testing" "github.com/fxamacker/cbor/v2" @@ -8,15 +9,21 @@ import ( ) func TestSessionTranscriptCBORRoundTrip(t *testing.T) { + deviceEngagementBytes, err := NewTaggedEncodedCBOR([]byte{1, 2, 3, 4}) + if err != nil { + t.Fatal(err) + } + eReaderKeyBytes := deviceEngagementBytes + sessionTranscripts := []SessionTranscript{ { - DeviceEngagementBytes: []byte{1, 2, 3, 4}, - EReaderKeyBytes: []byte{5, 6, 7, 8}, + DeviceEngagementBytes: *deviceEngagementBytes, + EReaderKeyBytes: *eReaderKeyBytes, Handover: QRHandover{}, }, { - DeviceEngagementBytes: []byte{1, 2, 3, 4}, - EReaderKeyBytes: []byte{5, 6, 7, 8}, + DeviceEngagementBytes: *deviceEngagementBytes, + EReaderKeyBytes: *eReaderKeyBytes, Handover: NFCHandover{ HandoverSelect: []byte{1, 2, 3, 4}, HandoverRequest: nil, @@ -36,7 +43,13 @@ func TestSessionTranscriptCBORRoundTrip(t *testing.T) { t.Fatal(err) } - if diff := cmp.Diff(&sessionTranscript, &sessionTranscriptUnmarshalled); diff != "" { + if diff := cmp.Diff( + &sessionTranscript, + &sessionTranscriptUnmarshalled, + cmp.FilterPath(func(p cmp.Path) bool { + return p.Last().Type() == reflect.TypeOf(TaggedEncodedCBOR{}) + }, cmp.Ignore()), + ); diff != "" { t.Fatal(diff) } }