@@ -16,7 +16,7 @@ import (
1616 "path/filepath"
1717 "time"
1818
19- "github.com/rbmk-project/rbmk/pkg/common /runtimex"
19+ "github.com/bassosimone /runtimex"
2020)
2121
2222// Config contains configuration for [New].
@@ -58,21 +58,21 @@ type Cert struct {
5858//
5959// This method panics on failure.
6060func (c * Cert ) WriteFiles (baseDir string ) {
61- runtimex .Try0 (os .WriteFile (filepath .Join (baseDir , "cert.pem" ), c .CertPEM , 0600 ))
62- runtimex .Try0 (os .WriteFile (filepath .Join (baseDir , "key.pem" ), c .KeyPEM , 0600 ))
61+ runtimex .PanicOnError0 (os .WriteFile (filepath .Join (baseDir , "cert.pem" ), c .CertPEM , 0600 ))
62+ runtimex .PanicOnError0 (os .WriteFile (filepath .Join (baseDir , "key.pem" ), c .KeyPEM , 0600 ))
6363}
6464
6565// New generates a self-signed certificate and key with SANs.
6666//
6767// This function panics on failure.
6868func New (config * Config ) * Cert {
6969 // Generate the private key
70- priv := runtimex .Try1 (ecdsa .GenerateKey (elliptic .P256 (), rand .Reader ))
70+ priv := runtimex .PanicOnError1 (ecdsa .GenerateKey (elliptic .P256 (), rand .Reader ))
7171
7272 // Build the certificate template
7373 notBefore := time .Now ()
7474 notAfter := notBefore .Add (365 * 24 * time .Hour )
75- serialNumber := runtimex .Try1 (rand .Int (rand .Reader , new (big.Int ).Lsh (big .NewInt (1 ), 128 )))
75+ serialNumber := runtimex .PanicOnError1 (rand .Int (rand .Reader , new (big.Int ).Lsh (big .NewInt (1 ), 128 )))
7676 template := x509.Certificate {
7777 SerialNumber : serialNumber ,
7878 Subject : pkix.Name {
@@ -91,12 +91,12 @@ func New(config *Config) *Cert {
9191 template .IPAddresses = config .IPAddrs
9292
9393 // Generate the certificate proper and encoded to PEM
94- certDER := runtimex .Try1 (x509 .CreateCertificate (
94+ certDER := runtimex .PanicOnError1 (x509 .CreateCertificate (
9595 rand .Reader , & template , & template , & priv .PublicKey , priv ))
9696 certPEM := pem .EncodeToMemory (& pem.Block {Type : "CERTIFICATE" , Bytes : certDER })
9797
9898 // Generate the private key in PEM format
99- keyPEM := runtimex .Try1 (x509 .MarshalECPrivateKey (priv ))
99+ keyPEM := runtimex .PanicOnError1 (x509 .MarshalECPrivateKey (priv ))
100100 keyPEMBytes := pem .EncodeToMemory (& pem.Block {Type : "EC PRIVATE KEY" , Bytes : keyPEM })
101101
102102 // Return the results
0 commit comments