func TestESTools(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	assert.Logf("testing \"ECDSA\" tools")
	// Generate keys and PEMs.
	privateKeyIn, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
	assert.Nil(err)
	privateBytes, err := x509.MarshalECPrivateKey(privateKeyIn)
	assert.Nil(err)
	privateBlock := pem.Block{
		Type:  "EC PRIVATE KEY",
		Bytes: privateBytes,
	}
	privatePEM := pem.EncodeToMemory(&privateBlock)
	publicBytes, err := x509.MarshalPKIXPublicKey(privateKeyIn.Public())
	assert.Nil(err)
	publicBlock := pem.Block{
		Type:  "EC PUBLIC KEY",
		Bytes: publicBytes,
	}
	publicPEM := pem.EncodeToMemory(&publicBlock)
	assert.NotNil(publicPEM)
	// Now read them.
	buf := bytes.NewBuffer(privatePEM)
	privateKeyOut, err := jwt.ReadECPrivateKey(buf)
	assert.Nil(err)
	buf = bytes.NewBuffer(publicPEM)
	publicKeyOut, err := jwt.ReadECPublicKey(buf)
	assert.Nil(err)
	// And as a last step check if they are correctly usable.
	claims := initClaims()
	jwtEncode, err := jwt.Encode(claims, privateKeyOut, jwt.ES512)
	assert.Nil(err)
	parts := strings.Split(jwtEncode.String(), ".")
	assert.Length(parts, 3)
	jwtVerify, err := jwt.Verify(jwtEncode.String(), publicKeyOut)
	assert.Nil(err)
	assert.Equal(jwtEncode.Algorithm(), jwtVerify.Algorithm())
	assert.Equal(jwtEncode.String(), jwtVerify.String())
	testClaims(assert, jwtVerify.Claims())
}
// TestESTools tests the tools for the reading of PEM encoded
// ECDSA keys.
TestESTools tests the tools for the reading of PEM encoded
ECDSA keys.
// TestESTools tests the tools for the reading of PEM encoded // ECDSA keys .
func TestESTools(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	assert.Logf("testing \"ECDSA\" tools")
	privateKeyIn, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
	assert.Nil(err)
	privateBytes, err := x509.MarshalECPrivateKey(privateKeyIn)
	assert.Nil(err)
	privateBlock := pem.Block{
		Type:  "EC PRIVATE KEY",
		Bytes: privateBytes,
	}
	privatePEM := pem.EncodeToMemory(&privateBlock)
	publicBytes, err := x509.MarshalPKIXPublicKey(privateKeyIn.Public())
	assert.Nil(err)
	publicBlock := pem.Block{
		Type:  "EC PUBLIC KEY",
		Bytes: publicBytes,
	}
	publicPEM := pem.EncodeToMemory(&publicBlock)
	assert.NotNil(publicPEM)
	buf := bytes.NewBuffer(privatePEM)
	privateKeyOut, err := jwt.ReadECPrivateKey(buf)
	assert.Nil(err)
	buf = bytes.NewBuffer(publicPEM)
	publicKeyOut, err := jwt.ReadECPublicKey(buf)
	assert.Nil(err)
	claims := initClaims()
	jwtEncode, err := jwt.Encode(claims, privateKeyOut, jwt.ES512)
	assert.Nil(err)
	parts := strings.Split(jwtEncode.String(), ".")
	assert.Length(parts, 3)
	jwtVerify, err := jwt.Verify(jwtEncode.String(), publicKeyOut)
	assert.Nil(err)
	assert.Equal(jwtEncode.Algorithm(), jwtVerify.Algorithm())
	assert.Equal(jwtEncode.String(), jwtVerify.String())
	testClaims(assert, jwtVerify.Claims())
}
func TestESTools ( t * testing . T ) { assert := audit . NewTestingAssertion ( t , true ) assert . Logf ( " \" \" " ) privateKeyIn , err := ecdsa . GenerateKey ( elliptic . P256 ( ) , rand . Reader ) assert . Nil ( err ) privateBytes , err := x509 . MarshalECPrivateKey ( privateKeyIn ) assert . Nil ( err ) privateBlock := pem . Block { Type : " " , Bytes : privateBytes , } privatePEM := pem . EncodeToMemory ( & privateBlock ) publicBytes , err := x509 . MarshalPKIXPublicKey ( privateKeyIn . Public ( ) ) assert . Nil ( err ) publicBlock := pem . Block { Type : " " , Bytes : publicBytes , } publicPEM := pem . EncodeToMemory ( & publicBlock ) assert . NotNil ( publicPEM ) buf := bytes . NewBuffer ( privatePEM ) privateKeyOut , err := jwt . ReadECPrivateKey ( buf ) assert . Nil ( err ) buf = bytes . NewBuffer ( publicPEM ) publicKeyOut , err := jwt . ReadECPublicKey ( buf ) assert . Nil ( err ) claims := initClaims ( ) jwtEncode , err := jwt . Encode ( claims , privateKeyOut , jwt . ES512 ) assert . Nil ( err ) parts := strings . Split ( jwtEncode . String ( ) , " " ) assert . Length ( parts , 3 ) jwtVerify , err := jwt . Verify ( jwtEncode . String ( ) , publicKeyOut ) assert . Nil ( err ) assert . Equal ( jwtEncode . Algorithm ( ) , jwtVerify . Algorithm ( ) ) assert . Equal ( jwtEncode . String ( ) , jwtVerify . String ( ) ) testClaims ( assert , jwtVerify . Claims ( ) ) }
TestESTools tests the tools for the reading of PEM encoded
ECDSA keys.
TestESTools tests the tools for the reading of PEM encoded ECDSA keys .
// Generate keys and PEMs. // Now read them. // And as a last step check if they are correctly usable.