Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update to fxamacker/cbor v2
  • Loading branch information
e3b0c442 committed Apr 13, 2020
commit 6dcae398ce8e3f98f61d46dad3ad02e77dfc1bd3
5 changes: 3 additions & 2 deletions attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"crypto/x509"
"encoding/asn1"

"github.com/fxamacker/cbor"
"github.com/fxamacker/cbor/v2"
)

var idFidoGenCeAaguid asn1.ObjectIdentifier = asn1.ObjectIdentifier([]int{1, 3, 6, 1, 4, 1, 45724, 1, 1, 4})
Expand Down Expand Up @@ -37,7 +37,8 @@ func (ao *AttestationObject) MarshalBinary() (data []byte, err error) {
AttStmt: ao.AttStmt,
}

return cbor.Marshal(&intermediate, cbor.CTAP2EncOptions())
em, _ := cbor.CTAP2EncOptions().EncMode()
return em.Marshal(&intermediate)
}

//UnmarshalBinary implements the BinaryUnmarshaler interface, and populates an
Expand Down
5 changes: 3 additions & 2 deletions attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"reflect"
"testing"

"github.com/fxamacker/cbor"
"github.com/fxamacker/cbor/v2"
)

func TestAttestationStatementFormatValid(t *testing.T) {
Expand Down Expand Up @@ -628,7 +628,8 @@ func TestVerifyPackedAttestationStatement(t *testing.T) {
if err != nil {
return nil, err
}
certCBOR, err := cbor.Marshal(cert, cbor.CTAP2EncOptions())
em, _ := cbor.CTAP2EncOptions().EncMode()
certCBOR, err := em.Marshal(cert)
if err != nil {
return nil, err
}
Expand Down
8 changes: 5 additions & 3 deletions authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/binary"
"io"

"github.com/fxamacker/cbor"
"github.com/fxamacker/cbor/v2"
)

//AuthenticatorData encodes contextual bindings made by the authenticator.
Expand Down Expand Up @@ -76,7 +76,8 @@ func (ad *AuthenticatorData) Encode(w io.Writer) error {
}

if ad.ED {
err = cbor.NewEncoder(w, cbor.CTAP2EncOptions()).Encode(ad.Extensions)
em, _ := cbor.CTAP2EncOptions().EncMode()
err = em.NewEncoder(w).Encode(ad.Extensions)
if err != nil {
return ErrEncodeAuthenticatorData.Wrap(NewError("Error writing extensions").Wrap(err))
}
Expand Down Expand Up @@ -202,7 +203,8 @@ func (acd *AttestedCredentialData) Encode(w io.Writer) error {
if uint16(n) != credLen {
return ErrEncodeAttestedCredentialData.Wrap(NewError("CredentialID wrote %d bytes, needed %d", n, credLen))
}
err = cbor.NewEncoder(w, cbor.CTAP2EncOptions()).Encode(acd.CredentialPublicKey)
em, _ := cbor.CTAP2EncOptions().EncMode()
err = em.NewEncoder(w).Encode(acd.CredentialPublicKey)
if err != nil {
return ErrEncodeAttestedCredentialData.Wrap(NewError("Error writing CredentialPublicKey").Wrap(err))
}
Expand Down
2 changes: 1 addition & 1 deletion cose.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"encoding/binary"
"math/big"

"github.com/fxamacker/cbor"
"github.com/fxamacker/cbor/v2"
)

//COSEKey represents a key decoded from COSE format.
Expand Down
61 changes: 36 additions & 25 deletions cose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"math/big"
"testing"

"github.com/fxamacker/cbor"
"github.com/fxamacker/cbor/v2"
)

func TestVerifySignature(t *testing.T) {
Expand All @@ -31,15 +31,17 @@ func TestVerifySignature(t *testing.T) {
Err error
}

goodP256X, _ := cbor.Marshal(goodP256Key.PublicKey.X.Bytes(), cbor.CTAP2EncOptions())
goodP256Y, _ := cbor.Marshal(goodP256Key.PublicKey.Y.Bytes(), cbor.CTAP2EncOptions())
em, _ := cbor.CTAP2EncOptions().EncMode()

good1024N, _ := cbor.Marshal(good1024Key.PublicKey.N.Bytes(), cbor.CTAP2EncOptions())
goodP256X, _ := em.Marshal(goodP256Key.PublicKey.X.Bytes())
goodP256Y, _ := em.Marshal(goodP256Key.PublicKey.Y.Bytes())

good1024N, _ := em.Marshal(good1024Key.PublicKey.N.Bytes())
good1024EBuf := &bytes.Buffer{}
binary.Write(good1024EBuf, binary.BigEndian, int32(good1024Key.PublicKey.E))
good1024E, _ := cbor.Marshal(good1024EBuf.Bytes(), cbor.CTAP2EncOptions())
good1024E, _ := em.Marshal(good1024EBuf.Bytes())

good25519X, _ := cbor.Marshal(good25519Pub, cbor.CTAP2EncOptions())
good25519X, _ := em.Marshal(good25519Pub)

tests := []verifyTest{
{
Expand Down Expand Up @@ -419,7 +421,8 @@ func TestVerifySignature(t *testing.T) {
if test.RawKey != nil {
rawKey = test.RawKey
} else {
rawKey, err = cbor.Marshal(test.COSEKey, cbor.CTAP2EncOptions())
em, _ := cbor.CTAP2EncOptions().EncMode()
rawKey, err = em.Marshal(test.COSEKey)
if err != nil {
t.Fatalf("Error marshaling test key: %v", err)
}
Expand Down Expand Up @@ -454,15 +457,17 @@ func TestDecodePublicKey(t *testing.T) {
Err error
}

goodP256X, _ := cbor.Marshal(goodP256Key.PublicKey.X.Bytes(), cbor.CTAP2EncOptions())
goodP256Y, _ := cbor.Marshal(goodP256Key.PublicKey.Y.Bytes(), cbor.CTAP2EncOptions())
em, _ := cbor.CTAP2EncOptions().EncMode()

goodP256X, _ := em.Marshal(goodP256Key.PublicKey.X.Bytes())
goodP256Y, _ := em.Marshal(goodP256Key.PublicKey.Y.Bytes())

good1024N, _ := cbor.Marshal(good1024Key.PublicKey.N.Bytes(), cbor.CTAP2EncOptions())
good1024N, _ := em.Marshal(good1024Key.PublicKey.N.Bytes())
good1024EBuf := &bytes.Buffer{}
binary.Write(good1024EBuf, binary.BigEndian, int32(good1024Key.PublicKey.E))
good1024E, _ := cbor.Marshal(good1024EBuf.Bytes(), cbor.CTAP2EncOptions())
good1024E, _ := em.Marshal(good1024EBuf.Bytes())

good25519X, _ := cbor.Marshal(good25519Pub, cbor.CTAP2EncOptions())
good25519X, _ := em.Marshal(good25519Pub)

tests := []decodeTest{
{
Expand Down Expand Up @@ -549,14 +554,16 @@ func TestDecodeECDSAPublicKey(t *testing.T) {
Err error
}

goodP256X, _ := cbor.Marshal(goodP256Key.PublicKey.X.Bytes(), cbor.CTAP2EncOptions())
goodP256Y, _ := cbor.Marshal(goodP256Key.PublicKey.Y.Bytes(), cbor.CTAP2EncOptions())
em, _ := cbor.CTAP2EncOptions().EncMode()

goodP256X, _ := em.Marshal(goodP256Key.PublicKey.X.Bytes())
goodP256Y, _ := em.Marshal(goodP256Key.PublicKey.Y.Bytes())

goodP384X, _ := cbor.Marshal(goodP384Key.PublicKey.X.Bytes(), cbor.CTAP2EncOptions())
goodP384Y, _ := cbor.Marshal(goodP384Key.PublicKey.Y.Bytes(), cbor.CTAP2EncOptions())
goodP384X, _ := em.Marshal(goodP384Key.PublicKey.X.Bytes())
goodP384Y, _ := em.Marshal(goodP384Key.PublicKey.Y.Bytes())

goodP521X, _ := cbor.Marshal(goodP521Key.PublicKey.X.Bytes(), cbor.CTAP2EncOptions())
goodP521Y, _ := cbor.Marshal(goodP521Key.PublicKey.Y.Bytes(), cbor.CTAP2EncOptions())
goodP521X, _ := em.Marshal(goodP521Key.PublicKey.X.Bytes())
goodP521Y, _ := em.Marshal(goodP521Key.PublicKey.Y.Bytes())

tests := []decodeECDSATest{
{
Expand Down Expand Up @@ -794,20 +801,22 @@ func TestDecodeRSAPublicKey(t *testing.T) {
Err error
}

good1024N, _ := cbor.Marshal(good1024Key.PublicKey.N.Bytes(), cbor.CTAP2EncOptions())
em, _ := cbor.CTAP2EncOptions().EncMode()

good1024N, _ := em.Marshal(good1024Key.PublicKey.N.Bytes())
good1024EBuf := &bytes.Buffer{}
binary.Write(good1024EBuf, binary.BigEndian, int32(good1024Key.PublicKey.E))
good1024E, _ := cbor.Marshal(good1024EBuf.Bytes(), cbor.CTAP2EncOptions())
good1024E, _ := em.Marshal(good1024EBuf.Bytes())

good2048N, _ := cbor.Marshal(good2048Key.PublicKey.N.Bytes(), cbor.CTAP2EncOptions())
good2048N, _ := em.Marshal(good2048Key.PublicKey.N.Bytes())
good2048EBuf := &bytes.Buffer{}
binary.Write(good2048EBuf, binary.BigEndian, int32(good2048Key.PublicKey.E))
good2048E, _ := cbor.Marshal(good2048EBuf.Bytes(), cbor.CTAP2EncOptions())
good2048E, _ := em.Marshal(good2048EBuf.Bytes())

good4096N, _ := cbor.Marshal(good4096Key.PublicKey.N.Bytes(), cbor.CTAP2EncOptions())
good4096N, _ := em.Marshal(good4096Key.PublicKey.N.Bytes())
good4096EBuf := &bytes.Buffer{}
binary.Write(good4096EBuf, binary.BigEndian, int32(good4096Key.PublicKey.E))
good4096E, _ := cbor.Marshal(good4096EBuf.Bytes(), cbor.CTAP2EncOptions())
good4096E, _ := em.Marshal(good4096EBuf.Bytes())

tests := []decodeRSATest{
{
Expand Down Expand Up @@ -1101,7 +1110,9 @@ func TestDecodeEd25519PublicKey(t *testing.T) {
Err error
}

goodKeyX, err := cbor.Marshal(good25519Pub, cbor.CTAP2EncOptions())
em, _ := cbor.CTAP2EncOptions().EncMode()

goodKeyX, err := em.Marshal(good25519Pub)
if err != nil {
t.Fatalf("Error marshalig pubkey: %v", err)
}
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/e3b0c442/warp

go 1.13

require (
github.com/fxamacker/cbor v1.5.0
github.com/x448/float16 v0.8.4 // indirect
)
require github.com/fxamacker/cbor/v2 v2.2.0
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
github.com/fxamacker/cbor v1.5.0 h1:idAiyeNSq/jeG9FPbCLVZLFJjsxP+g40a3UrXFapumw=
github.com/fxamacker/cbor v1.5.0/go.mod h1:UjdWSysJckWsChYy9I5zMbkGvK4xXDR+LmDb8kPGYgA=
github.com/x448/float16 v0.8.3 h1:i2Y5SfvnmNqonyrBxsp8I1AuTm+MW+kyxLES3w9dikk=
github.com/x448/float16 v0.8.3/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/fxamacker/cbor/v2 v2.2.0 h1:6eXqdDDe588rSYAi1HfZKbx6YYQO4mxQ9eC6xYpU/JQ=
github.com/fxamacker/cbor/v2 v2.2.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
2 changes: 1 addition & 1 deletion registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"reflect"
"testing"

"github.com/fxamacker/cbor"
"github.com/fxamacker/cbor/v2"
)

type testRP struct {
Expand Down
10 changes: 6 additions & 4 deletions warp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"reflect"
"testing"

"github.com/fxamacker/cbor"
"github.com/fxamacker/cbor/v2"
)

var goodP256Key *ecdsa.PrivateKey
Expand Down Expand Up @@ -111,11 +111,13 @@ func TestMain(m *testing.M) {
log.Fatalf("Key gen error: %v", err)
}

goodP256X, err = cbor.Marshal(goodP256Key.PublicKey.X.Bytes(), cbor.CTAP2EncOptions())
em, _ := cbor.CTAP2EncOptions().EncMode()

goodP256X, err = em.Marshal(goodP256Key.PublicKey.X.Bytes())
if err != nil {
log.Fatalf("X marshal err: %v", err)
}
goodP256Y, err = cbor.Marshal(goodP256Key.PublicKey.Y.Bytes(), cbor.CTAP2EncOptions())
goodP256Y, err = em.Marshal(goodP256Key.PublicKey.Y.Bytes())
if err != nil {
log.Fatalf("Y marshal err: %v", err)
}
Expand All @@ -128,7 +130,7 @@ func TestMain(m *testing.M) {
Y: goodP256Y,
}

goodP256Raw, err = cbor.Marshal(goodP256COSE, cbor.CTAP2EncOptions())
goodP256Raw, err = em.Marshal(goodP256COSE)
if err != nil {
log.Fatalf("COSEKey marshal err: %v", err)
}
Expand Down