assertstest

package
v0.0.0-...-b918686 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2016 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package assertstest provides helpers for testing code that involves assertions.

Index

Constants

View Source
const (
	DevKey = `` /* 3349-byte string literal not displayed */

	DevKeyID = "b52cf438a2d078f7"

	DevKeyFingerprint = "42a3050d365c10d5c093abeeb52cf438a2d078f7"
)

A sample developer key. See systestkeys for a prebuilt set of trusted keys and assertions.

Variables

This section is empty.

Functions

func GPGImportKey

func GPGImportKey(homedir, armoredKey string)

GPGImportKey imports the given PGP armored key into the GnuPG setup at homedir. It panics on error.

func GenerateKey

func GenerateKey(bits int) (asserts.PrivateKey, *packet.PrivateKey)

GenerateKey generates a private/public key pair of the given bits. It panics on error.

func NewAccount

func NewAccount(db SignerDB, username string, otherHeaders map[string]string, keyID string) *asserts.Account

NewAccount creates an account assertion for username, it fills in values for other missing headers as needed. It panics on error.

func NewAccountKey

func NewAccountKey(db SignerDB, acct *asserts.Account, otherHeaders map[string]string, pubKey asserts.PublicKey, keyID string) *asserts.AccountKey

NewAccountKey creates an account-key assertion for the account, it fills in values for missing headers as needed. In panics on error.

func ReadPrivKey

func ReadPrivKey(pk string) (asserts.PrivateKey, *packet.PrivateKey)

ReadPrivKey reads a PGP private key (either armored or simply base64 encoded). It panics on error.

Types

type SignerDB

type SignerDB interface {
	Sign(assertType *asserts.AssertionType, headers map[string]string, body []byte, keyID string) (asserts.Assertion, error)
}

A SignerDB can sign assertions using its key pairs.

type SigningDB

type SigningDB struct {
	AuthorityID string
	KeyID       string

	*asserts.Database
}

SigningDB embeds a signing assertion database with a default private key and assigned authority id. Sign will use the assigned authority id. "" can be passed for keyID to Sign and PublicKey to use the default key.

func NewSigningDB

func NewSigningDB(authorityID string, privKey asserts.PrivateKey) *SigningDB

NewSigningDB creates a test signing assertion db with the given defaults. It panics on error.

func (*SigningDB) PublicKey

func (db *SigningDB) PublicKey(keyID string) (asserts.PublicKey, error)

func (*SigningDB) Sign

func (db *SigningDB) Sign(assertType *asserts.AssertionType, headers map[string]string, body []byte, keyID string) (asserts.Assertion, error)

type StoreStack

type StoreStack struct {
	// Trusted authority assertions.
	TrustedAccount *asserts.Account
	TrustedKey     *asserts.AccountKey
	Trusted        []asserts.Assertion

	// Signing assertion db that signs with the root private key.
	RootSigning *SigningDB

	// The store-like signing functionality that signs with a store key, setup to also store assertions if desired. It stores a default account-key for the store private key, see also the StoreStack.Key method.
	*SigningDB
}

StoreStack realises a store-like set of founding trusted assertions and signing setup.

func NewStoreStack

func NewStoreStack(authorityID string, rootPrivKey, storePrivKey asserts.PrivateKey) *StoreStack

NewStoreStack creates a new store assertion stack. It panics on error.

func (*StoreStack) StoreAccountKey

func (ss *StoreStack) StoreAccountKey(keyID string) *asserts.AccountKey

StoreAccountKey retrieves one of the account-key assertions for the signing keys of the simulated store signing database. "" for keyID means the default one. It panics on error.

Jump to

Keyboard shortcuts

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