certdb

package
v0.0.0-...-57a9ce0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package certdb provides a simplistic ORM to communicate with an SQL database for storage

Example
db, err := certdb.NewCertificateRequestsRepository("./certs.db", "CertificateReq")
if err != nil {
	log.Fatalln(err)
}
_, err = db.Create(ValidCSR2)
if err != nil {
	log.Fatalln(err)
}
_, err = db.Update(ValidCSR2, ValidCert2)
if err != nil {
	log.Fatalln(err)
}
entry, err := db.Retrieve(ValidCSR2)
if err != nil {
	log.Fatalln(err)
}
if entry.Certificate != ValidCert2 {
	log.Fatalln("Retrieved Certificate doesn't match Stored Certificate")
}
err = db.Close()
if err != nil {
	log.Fatalln(err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CertificateMatchesCSR

func CertificateMatchesCSR(cert string, csr string) error

CertificateMatchesCSR makes sure that the given certificate and CSR match. The given CSR and Cert must pass their respective validation functions The given cert and CSR must share the same public key

func ValidateCertificate

func ValidateCertificate(cert string) error

ValidateCertificate validates the given Cert string to the following: The cert string must be a valid PEM string, and should be of type CERTIFICATE The PEM string should be able to be parsed into a x509 Certificate

func ValidateCertificateRequest

func ValidateCertificateRequest(csr string) error

ValidateCertificateRequest validates the given CSR string to the following: The string must be a valid PEM string, and should be of type CERTIFICATE REQUEST The PEM string should be able to be parsed into a x509 Certificate Request

Types

type CertificateRequest

type CertificateRequest struct {
	ID          int
	CSR         string
	Certificate string
}

A CertificateRequest struct represents an entry in the database. The object contains a Certificate Request, its matching Certificate if any, and the row ID.

type CertificateRequestsRepository

type CertificateRequestsRepository struct {
	// contains filtered or unexported fields
}

CertificateRequestRepository is the object used to communicate with the established repository.

func NewCertificateRequestsRepository

func NewCertificateRequestsRepository(databasePath string, tableName string) (*CertificateRequestsRepository, error)

NewCertificateRequestsRepository connects to a given table in a given database, stores the connection information and returns an object containing the information. The database path must be a valid file path or ":memory:". The table will be created if it doesn't exist in the format expected by the package.

func (*CertificateRequestsRepository) Close

Close closes the connection to the repository cleanly.

func (*CertificateRequestsRepository) Create

func (db *CertificateRequestsRepository) Create(csr string) (int64, error)

Create creates a new entry in the repository. The given CSR must be valid and unique

func (*CertificateRequestsRepository) Delete

func (db *CertificateRequestsRepository) Delete(id string) (int64, error)

Delete removes a CSR from the database alongside the certificate that may have been generated for it.

func (*CertificateRequestsRepository) Retrieve

Retrieve gets a given CSR from the repository. It returns the row id and matching certificate alongside the CSR in a CertificateRequest object.

func (*CertificateRequestsRepository) RetrieveAll

RetrieveAll gets every CertificateRequest entry in the table.

func (*CertificateRequestsRepository) Update

func (db *CertificateRequestsRepository) Update(id string, cert string) (int64, error)

Update adds a new cert to the given CSR in the repository. The given certificate must share the public key of the CSR and must be valid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL