saltpack

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(l Logger)

SetLogger sets package log

Types

type BoxKey

type BoxKey struct {
	ksaltpack.BoxSecretKey
	// contains filtered or unexported fields
}

BoxKey is a wrapper for keyup.BoxKey to support a ksaltpack.BoxKey.

func GenerateBoxKey

func GenerateBoxKey() BoxKey

GenerateBoxKey creates a BoxKey.

func NewBoxKey

func NewBoxKey(bk *keyup.BoxKey) BoxKey

NewBoxKey creates a BoxKey from a keyup.BoxKey.

func (BoxKey) Box

func (k BoxKey) Box(receiver ksaltpack.BoxPublicKey, nonce ksaltpack.Nonce, msg []byte) []byte

Box (for ksaltpack.BoxSecretKey)

func (BoxKey) GetPublicKey

func (k BoxKey) GetPublicKey() ksaltpack.BoxPublicKey

GetPublicKey (for ksaltpack.BoxSecretKey)

func (BoxKey) Precompute

Precompute (for ksaltpack.BoxSecretKey)

func (BoxKey) Unbox

func (k BoxKey) Unbox(sender ksaltpack.BoxPublicKey, nonce ksaltpack.Nonce, msg []byte) ([]byte, error)

Unbox (for ksaltpack.BoxSecretKey)

type BoxPublicKey

type BoxPublicKey struct {
	ksaltpack.BoxPublicKey
	// contains filtered or unexported fields
}

BoxPublicKey is a wrapper for keyup.BoxPublicKey to support a ksaltpack.BoxPublicKey.

func NewBoxPublicKey

func NewBoxPublicKey(pk keyup.BoxPublicKey) BoxPublicKey

NewBoxPublicKey from byte array.

func (BoxPublicKey) CreateEphemeralKey

func (p BoxPublicKey) CreateEphemeralKey() (ksaltpack.BoxSecretKey, error)

CreateEphemeralKey (for ksaltpack.BoxPublicKey)

func (BoxPublicKey) HideIdentity

func (p BoxPublicKey) HideIdentity() bool

HideIdentity (for ksaltpack.BoxPublicKey)

func (BoxPublicKey) ToKID

func (p BoxPublicKey) ToKID() []byte

ToKID (for ksaltpack.BoxPublicKey)

func (BoxPublicKey) ToRawBoxKeyPointer

func (p BoxPublicKey) ToRawBoxKeyPointer() *ksaltpack.RawBoxKey

ToRawBoxKeyPointer (for ksaltpack.BoxPublicKey)

type LogLevel

type LogLevel int

LogLevel ...

const (
	// DebugLevel ...
	DebugLevel LogLevel = 3
	// InfoLevel ...
	InfoLevel LogLevel = 2
	// WarnLevel ...
	WarnLevel LogLevel = 1
	// ErrLevel ...
	ErrLevel LogLevel = 0
)

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

Logger interface used in this package

type Saltpack

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

Saltpack provider.

func NewSaltpack

func NewSaltpack(ks *keyup.Keystore) *Saltpack

NewSaltpack creates a new keyup.CryptoProvider using saltpack.

Example
alice := keyup.GenerateKey()
bob := keyup.GenerateKey()

// Sigchain store
scs := keyup.NewSigchainStore(keyup.NewMem())

// Alice's keystore, save alice's key
ksa := keyup.NewKeystore()
ksa.SetKeyring(keyring.NewMem())
ksa.SetSigchainStore(scs)
if err := ksa.SaveKey(alice, true); err != nil {
	log.Fatal(err)
}
spa := NewSaltpack(ksa)
msg := []byte("Hey bob, it's alice. The passcode is 12345.")
// Alice encrypts
encrypted, sealErr := spa.Seal(msg, alice, bob.PublicKey())
if sealErr != nil {
	log.Fatal(sealErr)
}

// Bob's keystore, save bob's key and alice's public key
ksb := keyup.NewKeystore()
ksb.SetKeyring(keyring.NewMem())
ksb.SetSigchainStore(scs)
spb := NewSaltpack(ksb)
if err := ksb.SaveKey(bob, true); err != nil {
	log.Fatal(err)
}
// Bob decrypts
out, sender, openErr := spb.Open(encrypted)
if openErr != nil {
	log.Fatal(openErr)
}
if sender != alice.ID() {
	log.Fatalf("Sender not alice")
}
fmt.Printf("%s\n", string(out))
Output:

Hey bob, it's alice. The passcode is 12345.

func (*Saltpack) CreateEphemeralKey

func (s *Saltpack) CreateEphemeralKey() (ksaltpack.BoxSecretKey, error)

CreateEphemeralKey creates a random ephemeral key.

func (*Saltpack) GetAllBoxSecretKeys

func (s *Saltpack) GetAllBoxSecretKeys() []ksaltpack.BoxSecretKey

GetAllBoxSecretKeys returns all keys, needed if we want to support "hidden" receivers via trial and error.

func (*Saltpack) ImportBoxEphemeralKey

func (s *Saltpack) ImportBoxEphemeralKey(kid []byte) ksaltpack.BoxPublicKey

ImportBoxEphemeralKey imports the ephemeral key into BoxPublicKey format. This key has never been seen before, so will be ephemeral.

func (*Saltpack) LookupBoxPublicKey

func (s *Saltpack) LookupBoxPublicKey(kid []byte) ksaltpack.BoxPublicKey

LookupBoxPublicKey returns a public key given the specified key ID. For most cases, the key ID will be the key itself.

func (*Saltpack) LookupBoxSecretKey

func (s *Saltpack) LookupBoxSecretKey(kids [][]byte) (int, ksaltpack.BoxSecretKey)

LookupBoxSecretKey looks in the Keyring for the secret key corresponding to one of the given Key IDs. Returns the index and the key on success, or -1 and nil on failure.

func (*Saltpack) LookupSigningPublicKey

func (s *Saltpack) LookupSigningPublicKey(b []byte) ksaltpack.SigningPublicKey

LookupSigningPublicKey (for ksaltpack.SigKeyring)

func (*Saltpack) NewOpenStream

func (s *Saltpack) NewOpenStream(r io.Reader) (io.Reader, keyup.ID, error)

NewOpenStream ...

func (*Saltpack) NewSealStream

func (s *Saltpack) NewSealStream(w io.Writer, sender keyup.Key, recipients ...keyup.PublicKey) (io.WriteCloser, error)

NewSealStream ...

func (*Saltpack) NewSignStream

func (s *Saltpack) NewSignStream(w io.Writer, key keyup.Key, detached bool) (io.WriteCloser, error)

NewSignStream ...

func (*Saltpack) NewVerifyArmoredStream

func (s *Saltpack) NewVerifyArmoredStream(r io.Reader) (io.Reader, keyup.ID, error)

NewVerifyArmoredStream ...

func (*Saltpack) NewVerifyStream

func (s *Saltpack) NewVerifyStream(r io.Reader) (io.Reader, keyup.ID, error)

NewVerifyStream ...

func (*Saltpack) Open

func (s *Saltpack) Open(b []byte) ([]byte, keyup.ID, error)

Open ...

func (*Saltpack) Seal

func (s *Saltpack) Seal(b []byte, sender keyup.Key, recipients ...keyup.PublicKey) ([]byte, error)

Seal ...

func (*Saltpack) SetArmorBrand

func (s *Saltpack) SetArmorBrand(brand string)

SetArmorBrand sets the armor brand (if armored).

func (*Saltpack) SetArmored

func (s *Saltpack) SetArmored(b bool)

SetArmored to set whether data is armored.

func (*Saltpack) SetVersion

func (s *Saltpack) SetVersion(version ksaltpack.Version)

SetVersion sets version

func (*Saltpack) Sign

func (s *Saltpack) Sign(b []byte, key keyup.Key) ([]byte, error)

Sign (for keyup.CryptoProvider)

func (*Saltpack) SignDetached

func (s *Saltpack) SignDetached(b []byte, key keyup.Key) ([]byte, error)

SignDetached (for keyup.CryptoProvider)

func (*Saltpack) Verify

func (s *Saltpack) Verify(b []byte) ([]byte, keyup.ID, error)

Verify (for keyup.CryptoProvider)

func (*Saltpack) VerifyDetached

func (s *Saltpack) VerifyDetached(sig []byte, b []byte) (keyup.ID, error)

VerifyDetached (for keyup.CryptoProvider)

type SignKey

type SignKey struct {
	ksaltpack.SigningSecretKey
	// contains filtered or unexported fields
}

SignKey is a wrapper for

func NewSignKey

func NewSignKey(sk *keyup.SignKey) *SignKey

NewSignKey creates SigningSecretKey from a keyup.SignKey.

func (*SignKey) GetPublicKey

func (k *SignKey) GetPublicKey() ksaltpack.SigningPublicKey

GetPublicKey (for ksaltpack.SigningSecretKey)

func (*SignKey) Sign

func (k *SignKey) Sign(message []byte) ([]byte, error)

Sign (for ksaltpack.SigningSecretKey)

type SignPublicKey

type SignPublicKey struct {
	ksaltpack.SigningPublicKey
	// contains filtered or unexported fields
}

SignPublicKey is a wrapper for keyup.SignPublicKey.

func NewSignPublicKey

func NewSignPublicKey(pk keyup.SignPublicKey) *SignPublicKey

NewSignPublicKey creates SignPublicKey for keyup.SignPublicKey.

func (SignPublicKey) ToKID

func (k SignPublicKey) ToKID() []byte

ToKID (for ksaltpack.SigningPublicKey)

func (SignPublicKey) Verify

func (k SignPublicKey) Verify(message []byte, signature []byte) error

Verify (for ksaltpack.SigningPublicKey)

Jump to

Keyboard shortcuts

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