mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 18:36:30 +02:00
* chore(deps): bump github.com/golangci/golangci-lint Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.48.0 to 1.50.0. - [Release notes](https://github.com/golangci/golangci-lint/releases) - [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md) - [Commits](https://github.com/golangci/golangci-lint/compare/v1.48.0...v1.50.0) --- updated-dependencies: - dependency-name: github.com/golangci/golangci-lint dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * lint Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Caleb Doxsey <cdoxsey@pomerium.com>
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package cryptutil
|
|
|
|
import (
|
|
"encoding/pem"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// generated using:
|
|
//
|
|
// openssl genpkey -algorithm x25519 -out priv.pem
|
|
// openssl pkey -in priv.pem -out pub.pem -pubout
|
|
var (
|
|
rawPrivateX25519Key = []byte(`-----BEGIN PRIVATE KEY-----
|
|
MC4CAQAwBQYDK2VuBCIEIKALoNgzCksH0v0Bc7Ghl8vGin4MAIKpmtZSmaMN0Vtb
|
|
-----END PRIVATE KEY-----
|
|
`)
|
|
rawPublicX25519Key = []byte(`-----BEGIN PUBLIC KEY-----
|
|
MCowBQYDK2VuAyEAk63g8PY1JJTkrranWTxGSd/yA5kAgJlPk4/srMKg9mg=
|
|
-----END PUBLIC KEY-----
|
|
`)
|
|
)
|
|
|
|
func TestPKCS8PrivateKey(t *testing.T) {
|
|
block, _ := pem.Decode(rawPrivateX25519Key)
|
|
|
|
kek, err := ParsePKCS8PrivateKey(block.Bytes)
|
|
assert.NoError(t, err)
|
|
assert.IsType(t, &PrivateKeyEncryptionKey{}, kek)
|
|
|
|
t.Run("marshal", func(t *testing.T) {
|
|
der, err := MarshalPKCS8PrivateKey(kek)
|
|
require.NoError(t, err)
|
|
actual := pem.EncodeToMemory(&pem.Block{
|
|
Type: "PRIVATE KEY",
|
|
Bytes: der,
|
|
})
|
|
assert.Equal(t, rawPrivateX25519Key, actual)
|
|
})
|
|
}
|
|
|
|
func TestPKIXPublicKey(t *testing.T) {
|
|
block, _ := pem.Decode(rawPublicX25519Key)
|
|
|
|
kek, err := ParsePKIXPublicKey(block.Bytes)
|
|
assert.NoError(t, err)
|
|
assert.IsType(t, &PublicKeyEncryptionKey{}, kek)
|
|
|
|
t.Run("marshal", func(t *testing.T) {
|
|
der, err := MarshalPKIXPublicKey(kek)
|
|
require.NoError(t, err)
|
|
actual := pem.EncodeToMemory(&pem.Block{
|
|
Type: "PUBLIC KEY",
|
|
Bytes: der,
|
|
})
|
|
assert.Equal(t, rawPublicX25519Key, actual)
|
|
})
|
|
}
|