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 ¶
- func CertificateMatchesCSR(cert string, csr string) error
- func ValidateCertificate(cert string) error
- func ValidateCertificateRequest(csr string) error
- type CertificateRequest
- type CertificateRequestsRepository
- func (db *CertificateRequestsRepository) Close() error
- func (db *CertificateRequestsRepository) Create(csr string) (int64, error)
- func (db *CertificateRequestsRepository) Delete(id string) (int64, error)
- func (db *CertificateRequestsRepository) Retrieve(id string) (CertificateRequest, error)
- func (db *CertificateRequestsRepository) RetrieveAll() ([]CertificateRequest, error)
- func (db *CertificateRequestsRepository) Update(id string, cert string) (int64, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CertificateMatchesCSR ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (db *CertificateRequestsRepository) Close() error
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 ¶
func (db *CertificateRequestsRepository) Retrieve(id string) (CertificateRequest, error)
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 ¶
func (db *CertificateRequestsRepository) RetrieveAll() ([]CertificateRequest, error)
RetrieveAll gets every CertificateRequest entry in the table.