add documentation
This commit is contained in:
parent
2c43111aec
commit
f9807c7ccb
32
types.go
32
types.go
|
@ -1,35 +1,51 @@
|
||||||
|
// Package pki provides an easier way to create crypto related structures
|
||||||
|
// with the intent of making the management of these structures easier for
|
||||||
|
// other programs.
|
||||||
|
// Currently it provides mechanisms to create private keys in ECDSA and RSA,
|
||||||
|
// create public keys, create certificate sign requests and certificates.
|
||||||
|
//
|
||||||
|
// To create a new private key, there are two ways
|
||||||
|
// for an ecdsa key
|
||||||
|
// private_key, err := NewPrivateKeyEcdsa(elliptic.P521())
|
||||||
|
// or for a RSA key
|
||||||
|
// private_key, err := NewPrivateKeyRSA(4096)
|
||||||
|
//
|
||||||
|
// Getting a private key from the private key can be done with
|
||||||
|
// public_key := private_key.Public()
|
||||||
package pki
|
package pki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto"
|
"crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// this file holds all the interfaces used in the program until it can be split
|
// This label is used as the type in the pem encoding of public keys.
|
||||||
// properly
|
|
||||||
|
|
||||||
const PemLabelPublic = "PUBLIC KEY"
|
const PemLabelPublic = "PUBLIC KEY"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// interface for any private key
|
// This is the common interface for all private keys.
|
||||||
PrivateKey interface {
|
PrivateKey interface {
|
||||||
// derive a public key from the private key
|
// Derive a new public key from the private key.
|
||||||
Public() PublicKey
|
Public() PublicKey
|
||||||
// Sign a message using the public key and the given hash method.
|
// Sign a message using the public key and the given hash method.
|
||||||
// To use a hash method, include the package
|
// To use a hash method, include the package
|
||||||
// import _ "crypto/sha512"
|
// import _ "crypto/sha512"
|
||||||
Sign(message []byte, hash crypto.Hash) ([]byte, error)
|
Sign(message []byte, hash crypto.Hash) ([]byte, error)
|
||||||
|
|
||||||
// return the private key structure
|
// Return the original go structure of the private key.
|
||||||
PrivateKey() crypto.PrivateKey
|
PrivateKey() crypto.PrivateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// interface for any public key
|
// This interface has to be implemented by every public key structure.
|
||||||
PublicKey interface {
|
PublicKey interface {
|
||||||
Pemmer
|
Pemmer
|
||||||
// use the public key to verify a message against a signature
|
// This function can be used to verify a message against a provided signature
|
||||||
|
// using the given hash function.
|
||||||
Verify(message []byte, signature []byte, hash crypto.Hash) (bool, error)
|
Verify(message []byte, signature []byte, hash crypto.Hash) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This interface is used by all crypto structures which need to be available
|
||||||
|
// in the pem format. The result can then be written to any structure
|
||||||
|
// implementing the io.Writer interface.
|
||||||
Pemmer interface {
|
Pemmer interface {
|
||||||
MarshalPem() (marshalledPemBlock, error)
|
MarshalPem() (marshalledPemBlock, error)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue