-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpss_encoding_test.go
40 lines (35 loc) · 1004 Bytes
/
pss_encoding_test.go
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
package tcrsa
import (
"crypto"
"crypto/rsa"
"crypto/sha256"
"github.com/stretchr/testify/assert"
"testing"
)
func TestPreparePssDocumentHash(t *testing.T) {
var (
pssEncodeTestMessage = "Hello World , Pss Encoding"
pssEncodingLeyLength = 4096
)
docHash := sha256.Sum256([]byte(pssEncodeTestMessage))
docPss, err := PreparePssDocumentHash(pssEncodingLeyLength, docHash[:], nil, &rsa.PSSOptions{
SaltLength: 0,
Hash: crypto.SHA256,
})
assert.NoError(t, err)
assert.Equal(t, pssEncodingLeyLength/8, len(docPss))
// test salt length
salt := sha256.Sum256([]byte("dddsss"))
_, err = PreparePssDocumentHash(pssEncodingLeyLength, docHash[:], salt[:], &rsa.PSSOptions{
SaltLength: 0,
Hash: crypto.SHA256,
})
assert.NoError(t, err)
//
salt02 := make([]byte, 30)
_, err = PreparePssDocumentHash(pssEncodingLeyLength, docHash[:], salt02[:], &rsa.PSSOptions{
SaltLength: 0,
Hash: crypto.SHA256,
})
assert.Equal(t, "salt length too short", err.Error())
}