...
1
16
17 package jose
18
19 import (
20 "crypto/rand"
21 "encoding/base64"
22 "encoding/hex"
23 "math/big"
24 "regexp"
25 )
26
27
28 func resetRandReader() {
29 RandReader = rand.Reader
30 }
31
32
33 func fromHexInt(base16 string) *big.Int {
34 re := regexp.MustCompile(`\s+`)
35 val, ok := new(big.Int).SetString(re.ReplaceAllString(base16, ""), 16)
36 if !ok {
37 panic("Invalid test data")
38 }
39 return val
40 }
41
42
43 func fromBase64Int(encoded string) *big.Int {
44 re := regexp.MustCompile(`\s+`)
45 val, err := base64.RawURLEncoding.DecodeString(re.ReplaceAllString(encoded, ""))
46 if err != nil {
47 panic("Invalid test data: " + err.Error())
48 }
49 return new(big.Int).SetBytes(val)
50 }
51
52
53 func fromHexBytes(base16 string) []byte {
54 re := regexp.MustCompile(`\s+`)
55 val, err := hex.DecodeString(re.ReplaceAllString(base16, ""))
56 if err != nil {
57 panic("Invalid test data")
58 }
59 return val
60 }
61
62
63 func fromBase64Bytes(b64 string) []byte {
64 re := regexp.MustCompile(`\s+`)
65 val, err := base64.StdEncoding.DecodeString(re.ReplaceAllString(b64, ""))
66 if err != nil {
67 panic("Invalid test data")
68 }
69 return val
70 }
71
72
73 func fromBase64URLBytes(b64 string) []byte {
74 re := regexp.MustCompile(`\s+`)
75 val, err := base64.RawURLEncoding.DecodeString(re.ReplaceAllString(b64, ""))
76 if err != nil {
77 panic("Invalid test data")
78 }
79 return val
80 }
81
View as plain text