-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into steve/current-release-readme
Signed-off-by: Steve Lasker <[email protected]>
- Loading branch information
Showing
7 changed files
with
262 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,7 @@ vendor/ | |
.DS_Store | ||
/cose-fuzz.zip | ||
/workdir/ | ||
|
||
# Editor files | ||
.vscode/ | ||
.idea/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.