From fae872100d45a05e64ac4a49d92b1be3eb495133 Mon Sep 17 00:00:00 2001 From: Alex Richards Date: Fri, 16 Aug 2024 18:51:12 +1200 Subject: [PATCH] chore: go fmt Signed-off-by: Alex Richards --- .gitignore | 1 + bench_test.go | 180 +++++++++++++++++++++++++------------------------- 2 files changed, 91 insertions(+), 90 deletions(-) diff --git a/.gitignore b/.gitignore index b04f6b0..9a26cee 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ vendor/ # Editor files .vscode/ +.idea/ diff --git a/bench_test.go b/bench_test.go index 9a95f96..a60d1aa 100644 --- a/bench_test.go +++ b/bench_test.go @@ -1,90 +1,90 @@ -package cose_test - -import ( - "io" - "testing" - - "github.com/veraison/go-cose" -) - -func newSign1Message() *cose.Sign1Message { - return &cose.Sign1Message{ - Headers: cose.Headers{ - Protected: cose.ProtectedHeader{ - cose.HeaderLabelAlgorithm: cose.AlgorithmES256, - }, - Unprotected: cose.UnprotectedHeader{ - cose.HeaderLabelKeyID: []byte{0x01}, - }, - }, - Payload: make([]byte, 100), - Signature: make([]byte, 32), - } -} - -type noSigner struct{} - -func (noSigner) Algorithm() cose.Algorithm { - return cose.AlgorithmES256 -} - -func (noSigner) Sign(_ io.Reader, digest []byte) ([]byte, error) { - return digest, nil -} - -func (noSigner) Verify(_, _ []byte) error { - return nil -} - -func BenchmarkSign1Message_MarshalCBOR(b *testing.B) { - msg := newSign1Message() - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - _, err := msg.MarshalCBOR() - if err != nil { - b.Fatal(err) - } - } -} - -func BenchmarkSign1Message_UnmarshalCBOR(b *testing.B) { - data, err := newSign1Message().MarshalCBOR() - if err != nil { - b.Fatal(err) - } - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - var m cose.Sign1Message - err = m.UnmarshalCBOR(data) - if err != nil { - b.Fatal(err) - } - } -} - -func BenchmarkSign1Message_Sign(b *testing.B) { - msg := newSign1Message() - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - msg.Signature = nil - err := msg.Sign(zeroSource{}, nil, noSigner{}) - if err != nil { - b.Fatal(err) - } - } -} - -func BenchmarkSign1Message_Verify(b *testing.B) { - msg := newSign1Message() - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - err := msg.Verify(nil, noSigner{}) - if err != nil { - b.Fatal(err) - } - } -} +package cose_test + +import ( + "io" + "testing" + + "github.com/veraison/go-cose" +) + +func newSign1Message() *cose.Sign1Message { + return &cose.Sign1Message{ + Headers: cose.Headers{ + Protected: cose.ProtectedHeader{ + cose.HeaderLabelAlgorithm: cose.AlgorithmES256, + }, + Unprotected: cose.UnprotectedHeader{ + cose.HeaderLabelKeyID: []byte{0x01}, + }, + }, + Payload: make([]byte, 100), + Signature: make([]byte, 32), + } +} + +type noSigner struct{} + +func (noSigner) Algorithm() cose.Algorithm { + return cose.AlgorithmES256 +} + +func (noSigner) Sign(_ io.Reader, digest []byte) ([]byte, error) { + return digest, nil +} + +func (noSigner) Verify(_, _ []byte) error { + return nil +} + +func BenchmarkSign1Message_MarshalCBOR(b *testing.B) { + msg := newSign1Message() + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, err := msg.MarshalCBOR() + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkSign1Message_UnmarshalCBOR(b *testing.B) { + data, err := newSign1Message().MarshalCBOR() + if err != nil { + b.Fatal(err) + } + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + var m cose.Sign1Message + err = m.UnmarshalCBOR(data) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkSign1Message_Sign(b *testing.B) { + msg := newSign1Message() + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + msg.Signature = nil + err := msg.Sign(zeroSource{}, nil, noSigner{}) + if err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkSign1Message_Verify(b *testing.B) { + msg := newSign1Message() + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + err := msg.Verify(nil, noSigner{}) + if err != nil { + b.Fatal(err) + } + } +}