~aw/patches

flounder: Remove cert.go v1 APPLIED

Adnan Maolood: 1
 Remove cert.go

 1 files changed, 0 insertions(+), 46 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~aw/patches/patches/20154/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH flounder] Remove cert.go Export this patch

---
This file contains unused functions.

 cert.go | 46 ----------------------------------------------
 1 file changed, 46 deletions(-)
 delete mode 100644 cert.go

diff --git a/cert.go b/cert.go
deleted file mode 100644
index e82a949..0000000
--- a/cert.go
@@ -1,46 +0,0 @@
package main

import (
	"crypto"
	"crypto/tls"
	"crypto/x509"
	"encoding/pem"
	"io"
	"os"
)

// writeCertificate writes the provided certificate and private key
// to path.crt and path.key respectively.
func writeCertificate(path string, cert tls.Certificate) error {
	// Write the certificate
	crtPath := path + ".crt"
	crtOut, err := os.OpenFile(crtPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		return err
	}
	if err := marshalX509Certificate(crtOut, cert.Leaf.Raw); err != nil {
		return err
	}

	// Write the private key
	keyPath := path + ".key"
	keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		return err
	}
	return marshalPrivateKey(keyOut, cert.PrivateKey)
}

// marshalX509Certificate writes a PEM-encoded version of the given certificate.
func marshalX509Certificate(w io.Writer, cert []byte) error {
	return pem.Encode(w, &pem.Block{Type: "CERTIFICATE", Bytes: cert})
}

// marshalPrivateKey writes a PEM-encoded version of the given private key.
func marshalPrivateKey(w io.Writer, priv crypto.PrivateKey) error {
	privBytes, err := x509.MarshalPKCS8PrivateKey(priv)
	if err != nil {
		return err
	}
	return pem.Encode(w, &pem.Block{Type: "PRIVATE KEY", Bytes: privBytes})
}
-- 
2.30.0