func TestRSTools(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	assert.Logf("testing \"RSA\" tools")
	// Generate keys and PEMs.
	privateKeyIn, err := rsa.GenerateKey(rand.Reader, 2048)
	assert.Nil(err)
	privateBytes := x509.MarshalPKCS1PrivateKey(privateKeyIn)
	privateBlock := pem.Block{
		Type:  "RSA PRIVATE KEY",
		Bytes: privateBytes,
	}
	privatePEM := pem.EncodeToMemory(&privateBlock)
	publicBytes, err := x509.MarshalPKIXPublicKey(privateKeyIn.Public())
	assert.Nil(err)
	publicBlock := pem.Block{
		Type:  "RSA PUBLIC KEY",
		Bytes: publicBytes,
	}
	publicPEM := pem.EncodeToMemory(&publicBlock)
	assert.NotNil(publicPEM)
	// Now read them.
	buf := bytes.NewBuffer(privatePEM)
	privateKeyOut, err := jwt.ReadRSAPrivateKey(buf)
	assert.Nil(err)
	buf = bytes.NewBuffer(publicPEM)
	publicKeyOut, err := jwt.ReadRSAPublicKey(buf)
	assert.Nil(err)
	// And as a last step check if they are correctly usable.
	claims := initClaims()
	jwtEncode, err := jwt.Encode(claims, privateKeyOut, jwt.RS512)
	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())
}
// TestRSTools tests the tools for the reading of PEM encoded
// RSA keys.
TestRSTools tests the tools for the reading of PEM encoded
RSA keys.
// TestRSTools tests the tools for the reading of PEM encoded // RSA keys .
func TestRSTools(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	assert.Logf("testing \"RSA\" tools")
	privateKeyIn, err := rsa.GenerateKey(rand.Reader, 2048)
	assert.Nil(err)
	privateBytes := x509.MarshalPKCS1PrivateKey(privateKeyIn)
	privateBlock := pem.Block{
		Type:  "RSA PRIVATE KEY",
		Bytes: privateBytes,
	}
	privatePEM := pem.EncodeToMemory(&privateBlock)
	publicBytes, err := x509.MarshalPKIXPublicKey(privateKeyIn.Public())
	assert.Nil(err)
	publicBlock := pem.Block{
		Type:  "RSA PUBLIC KEY",
		Bytes: publicBytes,
	}
	publicPEM := pem.EncodeToMemory(&publicBlock)
	assert.NotNil(publicPEM)
	buf := bytes.NewBuffer(privatePEM)
	privateKeyOut, err := jwt.ReadRSAPrivateKey(buf)
	assert.Nil(err)
	buf = bytes.NewBuffer(publicPEM)
	publicKeyOut, err := jwt.ReadRSAPublicKey(buf)
	assert.Nil(err)
	claims := initClaims()
	jwtEncode, err := jwt.Encode(claims, privateKeyOut, jwt.RS512)
	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 TestRSTools ( t * testing . T ) { assert := audit . NewTestingAssertion ( t , true ) assert . Logf ( " \" \" " ) privateKeyIn , err := rsa . GenerateKey ( rand . Reader , 2048 ) assert . Nil ( err ) privateBytes := x509 . MarshalPKCS1PrivateKey ( privateKeyIn ) 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 . ReadRSAPrivateKey ( buf ) assert . Nil ( err ) buf = bytes . NewBuffer ( publicPEM ) publicKeyOut , err := jwt . ReadRSAPublicKey ( buf ) assert . Nil ( err ) claims := initClaims ( ) jwtEncode , err := jwt . Encode ( claims , privateKeyOut , jwt . RS512 ) 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 ( ) ) }
TestRSTools tests the tools for the reading of PEM encoded
RSA keys.
TestRSTools tests the tools for the reading of PEM encoded RSA keys .
// Generate keys and PEMs. // Now read them. // And as a last step check if they are correctly usable.