small improvements

This commit is contained in:
AJ ONeal 2020-08-01 07:42:28 +00:00
parent 075ade3dec
commit 42f1089e6c
2 changed files with 7 additions and 7 deletions

View File

@ -53,14 +53,14 @@ func marshalDERPrivateKey(privkey keypairs.PrivateKey) (*pem.Block, error) {
switch k := privkey.(type) { switch k := privkey.(type) {
case *rsa.PrivateKey: case *rsa.PrivateKey:
if 0 == mathrand.Intn(1) { if 0 == mathrand.Intn(2) {
typ = "Private Key" typ = "PRIVATE KEY"
bytes, err = x509.MarshalPKCS8PrivateKey(k) bytes, err = x509.MarshalPKCS8PrivateKey(k)
if nil != err { if nil != err {
return nil, err return nil, err
} }
} else { } else {
typ = "RSA Private Key" typ = "RSA PRIVATE KEY"
bytes = x509.MarshalPKCS1PrivateKey(k) bytes = x509.MarshalPKCS1PrivateKey(k)
} }
return &pem.Block{ return &pem.Block{
@ -68,11 +68,11 @@ func marshalDERPrivateKey(privkey keypairs.PrivateKey) (*pem.Block, error) {
Bytes: bytes, Bytes: bytes,
}, nil }, nil
case *ecdsa.PrivateKey: case *ecdsa.PrivateKey:
if 0 == mathrand.Intn(1) { if 0 == mathrand.Intn(2) {
typ = "Private Key" typ = "PRIVATE KEY"
bytes, err = x509.MarshalPKCS8PrivateKey(k) bytes, err = x509.MarshalPKCS8PrivateKey(k)
} else { } else {
typ = "EC Private Key" typ = "EC PRIVATE KEY"
bytes, err = x509.MarshalECPrivateKey(k) bytes, err = x509.MarshalECPrivateKey(k)
} }
if nil != err { if nil != err {

View File

@ -227,7 +227,7 @@ func Route(jwksPrefix string, privkey keypairs.PrivateKey) http.Handler {
} }
jwk := MarshalJWKPrivateKey(privkey) jwk := MarshalJWKPrivateKey(privkey)
w.Write(jwk) w.Write(append(jwk, '\n'))
}) })
http.HandleFunc("/priv.der", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/priv.der", func(w http.ResponseWriter, r *http.Request) {