utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2016 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AESKeyLength is the default AES key length
	AESKeyLength = 32

	// NonceSize is the default NonceSize
	NonceSize = 24
)

Variables

View Source
var (
	// ErrRegistrationRequired Registration to the Membership Service required.
	ErrRegistrationRequired = errors.New("Registration to the Membership Service required.")

	// ErrNotInitialized Initialization required
	ErrNotInitialized = errors.New("Initialization required.")

	// ErrAlreadyInitialized Already initialized
	ErrAlreadyInitialized = errors.New("Already initialized.")

	// ErrAlreadyRegistered Already registered
	ErrAlreadyRegistered = errors.New("Already registered.")

	// ErrTransactionMissingCert Transaction missing certificate or signature
	ErrTransactionMissingCert = errors.New("Transaction missing certificate or signature.")

	// ErrInvalidTransactionSignature Invalid Transaction Signature
	ErrInvalidTransactionSignature = errors.New("Invalid Transaction Signature.")

	// ErrTransactionCertificate Missing Transaction Certificate
	ErrTransactionCertificate = errors.New("Missing Transaction Certificate.")

	// ErrTransactionSignature Missing Transaction Signature
	ErrTransactionSignature = errors.New("Missing Transaction Signature.")

	// ErrInvalidSignature Invalid Signature
	ErrInvalidSignature = errors.New("Invalid Signature.")

	// ErrInvalidReference Invalid reference
	ErrInvalidReference = errors.New("Invalid reference.")

	// ErrInvalidReference Invalid reference
	ErrNilArgument = errors.New("Nil argument.")

	// ErrNotImplemented Not implemented
	ErrNotImplemented = errors.New("Not implemented.")

	// ErrKeyStoreAlreadyInitialized Keystore already Initilized
	ErrKeyStoreAlreadyInitialized = errors.New("Keystore already Initilized.")

	// ErrEncrypt Encryption failed
	ErrEncrypt = errors.New("Encryption failed.")

	// ErrDecrypt Decryption failed
	ErrDecrypt = errors.New("Decryption failed.")

	// ErrDirrentChaincodeID ChaincodeIDs are different
	ErrDirrentChaincodeID = errors.New("ChaincodeIDs are different.")

	// ErrInvalidConfidentialityLevel Invalid confidentiality level
	ErrInvalidConfidentialityLevel = errors.New("Invalid confidentiality level")
)
View Source
var (
	DefaultCurve = elliptic.P384()
)
View Source
var (
	// TCertEncTCertIndex oid for TCertIndex
	TCertEncTCertIndex = asn1.ObjectIdentifier{1, 2, 3, 4, 5, 6, 7}
)

Functions

func AEStoEncryptedPEM

func AEStoEncryptedPEM(raw []byte, pwd []byte) ([]byte, error)

AEStoEncryptedPEM encapsulates an AES key in the encrypted PEM format

func AEStoPEM

func AEStoPEM(raw []byte) []byte

AEStoPEM encapsulates an AES key in the PEM format

func CBCDecrypt

func CBCDecrypt(key, src []byte) ([]byte, error)

CBCDecrypt decrypts using CBC mode

func CBCEncrypt

func CBCEncrypt(key, s []byte) ([]byte, error)

CBCEncrypt encrypts using CBC mode

func CBCPKCS7Decrypt

func CBCPKCS7Decrypt(key, src []byte) ([]byte, error)

CBCPKCS7Decrypt combines CBC decryption and PKCS7 unpadding

func CBCPKCS7Encrypt

func CBCPKCS7Encrypt(key, src []byte) ([]byte, error)

CBCPKCS7Encrypt combines CBC encryption and PKCS7 padding

func CheckCertAgainRoot

func CheckCertAgainRoot(x509Cert *x509.Certificate, certPool *x509.CertPool) ([][]*x509.Certificate, error)

func CheckCertAgainstSKAndRoot

func CheckCertAgainstSKAndRoot(x509Cert *x509.Certificate, privateKey interface{}, certPool *x509.CertPool) error

func CheckCertPKAgainstSK

func CheckCertPKAgainstSK(x509Cert *x509.Certificate, privateKey interface{}) error

func Clone

func Clone(src []byte) []byte

Clone clones the passed slice

func DERCertToPEM

func DERCertToPEM(der []byte) []byte

DERCertToPEM converts der to pem

func DERToPrivateKey

func DERToPrivateKey(der []byte) (interface{}, error)

DERToPrivateKey unmarshals a der to private key

func DERToX509Certificate

func DERToX509Certificate(asn1Data []byte) (*x509.Certificate, error)

DERToX509Certificate converts der to x509

func DecodeBase64

func DecodeBase64(in string) ([]byte, error)

DecodeBase64 decodes from Base64

func DirEmpty

func DirEmpty(path string) (bool, error)

DirEmpty checks if a directory is empty

func DirExists

func DirExists(path string) (bool, error)

DirExists checks if a directory exists

func DirMissingOrEmpty

func DirMissingOrEmpty(path string) (bool, error)

DirMissingOrEmpty checks is a directory is missin or empty

func ECDSASign

func ECDSASign(signKey interface{}, msg []byte) ([]byte, error)

ECDSASign signs

func ECDSASignDirect

func ECDSASignDirect(signKey interface{}, msg []byte) (*big.Int, *big.Int, error)

ECDSASignDirect signs

func ECDSAVerify

func ECDSAVerify(verKey interface{}, msg, signature []byte) (bool, error)

ECDSAVerify verifies

func EncodeBase64

func EncodeBase64(in []byte) string

EncodeBase64 encodes to Base64

func ErrToString

func ErrToString(err error) string

func FileMissing

func FileMissing(path string, name string) (bool, error)

FileMissing checks if a file is missing

func FilePathMissing

func FilePathMissing(path string) (bool, error)

FilePathMissing returns true if the path is missing, false otherwise.

func GenAESKey

func GenAESKey() ([]byte, error)

GenAESKey returns a random AES key of length AESKeyLength

func GetCriticalExtension

func GetCriticalExtension(cert *x509.Certificate, oid asn1.ObjectIdentifier) ([]byte, error)

GetCriticalExtension returns a requested critical extension. It also remove it from the list of unhandled critical extensions

func GetRandomBytes

func GetRandomBytes(len int) ([]byte, error)

GetRandomBytes returns len random looking bytes

func HMAC

func HMAC(key, x []byte) []byte

HMAC hmacs x using key key

func HMACTruncated

func HMACTruncated(key, x []byte, truncation int) []byte

HMACTruncated hmacs x using key key and truncate to truncation

func Hash

func Hash(msg []byte) []byte

Hash hashes the msh using the predefined hash function

func IntArrayEquals

func IntArrayEquals(a []int, b []int) bool

IntArrayEquals checks if the arrays of ints are the same

func IsTCPPortOpen

func IsTCPPortOpen(laddr string) error

IsTCPPortOpen checks the tcp port is open

func NewECDSAKey

func NewECDSAKey() (*ecdsa.PrivateKey, error)

NewECDSAKey generates a new ECDSA Key

func NewHash

func NewHash() hash.Hash

NewHash returns a new hash function

func NewSelfSignedCert

func NewSelfSignedCert() ([]byte, interface{}, error)

NewSelfSignedCert create a self signed certificate

func PEMtoAES

func PEMtoAES(raw []byte, pwd []byte) ([]byte, error)

PEMtoAES extracts from the PEM an AES key

func PEMtoCertificate

func PEMtoCertificate(raw []byte) (*x509.Certificate, error)

PEMtoCertificate converts pem to x509

func PEMtoCertificateAndDER

func PEMtoCertificateAndDER(raw []byte) (*x509.Certificate, []byte, error)

PEMtoCertificateAndDER converts pem to x509 and der

func PEMtoDER

func PEMtoDER(raw []byte) ([]byte, error)

PEMtoDER converts pem to der

func PEMtoPrivateKey

func PEMtoPrivateKey(raw []byte, pwd []byte) (interface{}, error)

PEMtoPrivateKey unmarshals a pem to private key

func PKCS7Padding

func PKCS7Padding(src []byte) []byte

PKCS7Padding pads as prescribed by the PKCS7 standard

func PKCS7UnPadding

func PKCS7UnPadding(src []byte) ([]byte, error)

PKCS7UnPadding unpads as prescribed by the PKCS7 standard

func PrivateKeyToDER

func PrivateKeyToDER(privateKey *ecdsa.PrivateKey) ([]byte, error)

PrivateKeyToDER marshals a private key to der

func PrivateKeyToEncryptedPEM

func PrivateKeyToEncryptedPEM(privateKey interface{}, pwd []byte) ([]byte, error)

PrivateKeyToEncryptedPEM converts a private key to an encrypted PEM

func PrivateKeyToPEM

func PrivateKeyToPEM(privateKey interface{}, pwd []byte) ([]byte, error)

PrivateKeyToPEM converts a private key to PEM

func PublicKeyToPEM

func PublicKeyToPEM(algo string, publicKey interface{}) ([]byte, error)

PublicKeyToPEM marshals a public key to the pem forma

func VerifySignCapability

func VerifySignCapability(tempSK interface{}, certPK interface{}) error

VerifySignCapability tests signing capabilities

Types

type ECDSASignature

type ECDSASignature struct {
	R, S *big.Int
}

ECDSASignature represents an ECDSA signature

type NodeConfiguration

type NodeConfiguration struct {
	Type string
	Name string
}

NodeConfiguration used for testing

func (*NodeConfiguration) GetEnrollmentID

func (conf *NodeConfiguration) GetEnrollmentID() string

GetEnrollmentID returns the enrollment ID

func (*NodeConfiguration) GetEnrollmentPWD

func (conf *NodeConfiguration) GetEnrollmentPWD() string

GetEnrollmentPWD returns the enrollment PWD

Jump to

Keyboard shortcuts

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