File: key_test.go

package info (click to toggle)
golang-github-docker-libtrust 0.0~git20150526.0.9cbd2a1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 288 kB
  • ctags: 297
  • sloc: makefile: 3
file content (80 lines) | stat: -rw-r--r-- 1,934 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package libtrust

import (
	"testing"
)

type generateFunc func() (PrivateKey, error)

func runGenerateBench(b *testing.B, f generateFunc, name string) {
	for i := 0; i < b.N; i++ {
		_, err := f()
		if err != nil {
			b.Fatalf("Error generating %s: %s", name, err)
		}
	}
}

func runFingerprintBench(b *testing.B, f generateFunc, name string) {
	b.StopTimer()
	// Don't count this relatively slow generation call.
	key, err := f()
	if err != nil {
		b.Fatalf("Error generating %s: %s", name, err)
	}
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		if key.KeyID() == "" {
			b.Fatalf("Error generating key ID for %s", name)
		}
	}
}

func BenchmarkECP256Generate(b *testing.B) {
	runGenerateBench(b, GenerateECP256PrivateKey, "P256")
}

func BenchmarkECP384Generate(b *testing.B) {
	runGenerateBench(b, GenerateECP384PrivateKey, "P384")
}

func BenchmarkECP521Generate(b *testing.B) {
	runGenerateBench(b, GenerateECP521PrivateKey, "P521")
}

func BenchmarkRSA2048Generate(b *testing.B) {
	runGenerateBench(b, GenerateRSA2048PrivateKey, "RSA2048")
}

func BenchmarkRSA3072Generate(b *testing.B) {
	runGenerateBench(b, GenerateRSA3072PrivateKey, "RSA3072")
}

func BenchmarkRSA4096Generate(b *testing.B) {
	runGenerateBench(b, GenerateRSA4096PrivateKey, "RSA4096")
}

func BenchmarkECP256Fingerprint(b *testing.B) {
	runFingerprintBench(b, GenerateECP256PrivateKey, "P256")
}

func BenchmarkECP384Fingerprint(b *testing.B) {
	runFingerprintBench(b, GenerateECP384PrivateKey, "P384")
}

func BenchmarkECP521Fingerprint(b *testing.B) {
	runFingerprintBench(b, GenerateECP521PrivateKey, "P521")
}

func BenchmarkRSA2048Fingerprint(b *testing.B) {
	runFingerprintBench(b, GenerateRSA2048PrivateKey, "RSA2048")
}

func BenchmarkRSA3072Fingerprint(b *testing.B) {
	runFingerprintBench(b, GenerateRSA3072PrivateKey, "RSA3072")
}

func BenchmarkRSA4096Fingerprint(b *testing.B) {
	runFingerprintBench(b, GenerateRSA4096PrivateKey, "RSA4096")
}