mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-23 05:57:19 +02:00
cryptutil: move to pkg dir, add token generator (#1029)
* cryptutil: move to pkg dir, add token generator * add gitignored files * add tests
This commit is contained in:
parent
b90885b4c1
commit
fae02791f5
48 changed files with 175 additions and 35 deletions
60
pkg/cryptutil/sign_test.go
Normal file
60
pkg/cryptutil/sign_test.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package cryptutil
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSign(t *testing.T) {
|
||||
message := []byte("Hello, world!")
|
||||
|
||||
key, err := NewSigningKey()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
signature, err := Sign(message, key)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if !Verify(message, signature, &key.PublicKey) {
|
||||
t.Error("signature was not correct")
|
||||
return
|
||||
}
|
||||
|
||||
message[0] ^= 0xff
|
||||
if Verify(message, signature, &key.PublicKey) {
|
||||
t.Error("signature was good for altered message")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSignWithP384(t *testing.T) {
|
||||
message := []byte("Hello, world!")
|
||||
|
||||
key, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
signature, err := Sign(message, key)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
if !Verify(message, signature, &key.PublicKey) {
|
||||
t.Error("signature was not correct")
|
||||
return
|
||||
}
|
||||
|
||||
message[0] ^= 0xff
|
||||
if Verify(message, signature, &key.PublicKey) {
|
||||
t.Error("signature was good for altered message")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue