// TestBadKeyRequest ensures that generating a key from a KeyRequest
// fails with an invalid algorithm, or an invalid RSA or ECDSA key
// size. An invalid ECDSA key size is any size other than 256, 384, or
// 521; an invalid RSA key size is any size less than 2048 bits.
TestBadKeyRequest ensures that generating a key from a KeyRequest
fails with an invalid algorithm, or an invalid RSA or ECDSA key
size. An invalid ECDSA key size is any size other than 256, 384, or
521; an invalid RSA key size is any size less than 2048 bits.
// TestBadKeyRequest ensures that generating a key from a KeyRequest // fails with an invalid algorithm or an invalid RSA or ECDSA key // size . An invalid ECDSA key size is any size other than 256 384 or // 521 ; an invalid RSA key size is any size less than 2048 bits .
func TestBadKeyRequest(t *testing.T) {
	kr := &KeyRequest{"yolocrypto", 1024}
	if _, err := kr.Generate(); err == nil {
		t.Fatal("Key generation should fail with invalid algorithm")
	} else if sa := kr.SigAlgo(); sa != x509.UnknownSignatureAlgorithm {
		t.Fatal("The wrong signature algorithm was returned from SigAlgo!")
	}
	kr.A = "ecdsa"
	if _, err := kr.Generate(); err == nil {
		t.Fatal("Key generation should fail with invalid key size")
	} else if sa := kr.SigAlgo(); sa != x509.ECDSAWithSHA1 {
		t.Fatal("The wrong signature algorithm was returned from SigAlgo!")
	}
	kr.A = "rsa"
	if _, err := kr.Generate(); err == nil {
		t.Fatal("Key generation should fail with invalid key size")
	} else if sa := kr.SigAlgo(); sa != x509.SHA1WithRSA {
		t.Fatal("The wrong signature algorithm was returned from SigAlgo!")
	}
	kr = &KeyRequest{"tobig", 9216}
	kr.A = "rsa"
	if _, err := kr.Generate(); err == nil {
		t.Fatal("Key generation should fail with invalid key size")
	} else if sa := kr.SigAlgo(); sa != x509.SHA512WithRSA {
		t.Fatal("The wrong signature algorithm was returned from SigAlgo!")
	}
}
func TestBadKeyRequest ( t * testing . T ) { kr := & KeyRequest { " " , 1024 } if _ , err := kr . Generate ( ) ; err == nil { t . Fatal ( " " ) } else if sa := kr . SigAlgo ( ) ; sa != x509 . UnknownSignatureAlgorithm { t . Fatal ( " " ) } kr . A = " " if _ , err := kr . Generate ( ) ; err == nil { t . Fatal ( " " ) } else if sa := kr . SigAlgo ( ) ; sa != x509 . ECDSAWithSHA1 { t . Fatal ( " " ) } kr . A = " " if _ , err := kr . Generate ( ) ; err == nil { t . Fatal ( " " ) } else if sa := kr . SigAlgo ( ) ; sa != x509 . SHA1WithRSA { t . Fatal ( " " ) } kr = & KeyRequest { " " , 9216 } kr . A = " " if _ , err := kr . Generate ( ) ; err == nil { t . Fatal ( " " ) } else if sa := kr . SigAlgo ( ) ; sa != x509 . SHA512WithRSA { t . Fatal ( " " ) } }
TestBadKeyRequest ensures that generating a key from a KeyRequest
fails with an invalid algorithm, or an invalid RSA or ECDSA key
size.
TestBadKeyRequest ensures that generating a key from a KeyRequest fails with an invalid algorithm or an invalid RSA or ECDSA key size .