File: algorithm_test.go

package info (click to toggle)
golang-github-notaryproject-tspclient-go 0.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 772 kB
  • sloc: makefile: 20
file content (51 lines) | stat: -rw-r--r-- 2,069 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright The Notary Project Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package oid

import (
	"crypto/x509"
	"encoding/asn1"
	"testing"
)

func TestToSignatureAlgorithm(t *testing.T) {
	tests := []struct {
		name       string
		digestAlg  asn1.ObjectIdentifier
		sigAlg     asn1.ObjectIdentifier
		wantResult x509.SignatureAlgorithm
	}{
		{"SHA256WithRSA", SHA256, RSA, x509.SHA256WithRSA},
		{"SHA384WithRSA", SHA384, RSA, x509.SHA384WithRSA},
		{"SHA512WithRSA", SHA512, RSA, x509.SHA512WithRSA},
		{"SHA256WithRSAPSS", SHA256, RSAPSS, x509.SHA256WithRSAPSS},
		{"SHA384WithRSAPSS", SHA384, RSAPSS, x509.SHA384WithRSAPSS},
		{"SHA512WithRSAPSS", SHA512, RSAPSS, x509.SHA512WithRSAPSS},
		{"SHA256WithRSA direct", SHA256WithRSA, SHA256WithRSA, x509.SHA256WithRSA},
		{"SHA384WithRSA direct", SHA384WithRSA, SHA384WithRSA, x509.SHA384WithRSA},
		{"SHA512WithRSA direct", SHA512WithRSA, SHA512WithRSA, x509.SHA512WithRSA},
		{"ECDSAWithSHA256", ECDSAWithSHA256, ECDSAWithSHA256, x509.ECDSAWithSHA256},
		{"ECDSAWithSHA384", ECDSAWithSHA384, ECDSAWithSHA384, x509.ECDSAWithSHA384},
		{"ECDSAWithSHA512", ECDSAWithSHA512, ECDSAWithSHA512, x509.ECDSAWithSHA512},
		{"UnknownSignatureAlgorithm", asn1.ObjectIdentifier{1, 2, 3}, asn1.ObjectIdentifier{4, 5, 6}, x509.UnknownSignatureAlgorithm},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if gotResult := ToSignatureAlgorithm(tt.digestAlg, tt.sigAlg); gotResult != tt.wantResult {
				t.Errorf("ToSignatureAlgorithm() = %v, want %v", gotResult, tt.wantResult)
			}
		})
	}
}