cipher

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2017 License: ISC Imports: 17 Imported by: 21

Documentation

Index

Constants

View Source
const (
	// AckLength is the length of an ack message.
	AckLength = 26
)

Variables

View Source
var (
	// ErrUnsupportedOp is returned when the attempted operation is unsupported.
	ErrUnsupportedOp = errors.New("operation unsupported")

	// ErrInvalidSignature is returned when the signature embedded in the
	// message is malformed or fails to verify (because of invalid checksum).
	ErrInvalidSignature = errors.New("invalid signature/verification failed")

	// ErrInvalidIdentity is returned when the provided address/identity is
	// unable to decrypt the given message.
	ErrInvalidIdentity = errors.New("invalid supplied identity/decryption failed")

	// ErrInvalidObjectType is returned when the given object is not of
	// the expected type.
	ErrInvalidObjectType = errors.New("invalid object type")
)

Functions

func ToIdentity

func ToIdentity(pubkey PubKeyObject) (identity.Public, error)

ToIdentity transforms a PubKeyObject to an identity.Public

Types

type Bitmessage

type Bitmessage struct {
	Public      identity.Public
	Destination *hash.Ripe
	Content     format.Encoding
}

Bitmessage is a representation of the data included in a bitmessage. It could be part of a message object or a broadcast object.

func (*Bitmessage) String

func (b *Bitmessage) String() string

type Broadcast

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

Broadcast represents a broadcast that has either been decrypted from the network or which we have created.

func CreateTaggedBroadcast

func CreateTaggedBroadcast(expires time.Time, bm *Bitmessage, tag *hash.Sha,
	private *identity.PrivateID) (*Broadcast, error)

CreateTaggedBroadcast creates a Broadcast that we send over the network, as opposed to one that we receive and decrypt.

func CreateTaglessBroadcast

func CreateTaglessBroadcast(expiration time.Time, bm *Bitmessage,
	private *identity.PrivateID) (*Broadcast, error)

CreateTaglessBroadcast creates a Broadcast that we send over the network, as opposed to one that we receive and decrypt.

func NewTaggedBroadcast

func NewTaggedBroadcast(msg *obj.TaggedBroadcast, address bmutil.Address) (*Broadcast, error)

NewTaggedBroadcast takes a broadcast we have received over the network and attempts to decrypt it.

func NewTaglessBroadcast

func NewTaglessBroadcast(msg *obj.TaglessBroadcast, address bmutil.Address) (*Broadcast, error)

NewTaglessBroadcast takes a broadcast we have received over the network and attempts to decrypt it.

func SignAndEncryptBroadcast

func SignAndEncryptBroadcast(expiration time.Time,
	msg *Bitmessage, tag *hash.Sha, privID *identity.PrivateID) (*Broadcast, error)

SignAndEncryptBroadcast signs and encrypts a Broadcast, populating the Signature and Encrypted fields using the provided private identity.

The private identity supplied should be of the sender. There are no checks against supplying invalid private identity.

func TryDecryptAndVerifyBroadcast

func TryDecryptAndVerifyBroadcast(msg obj.Broadcast, address bmutil.Address) (*Broadcast, error)

TryDecryptAndVerifyBroadcast tries to decrypt a wire.BroadcastObject of the public identity. If it fails, it returns ErrInvalidIdentity. If decryption succeeds, it verifies the embedded signature. If signature verification fails, it returns ErrInvalidSignature. Else, it returns nil.

All necessary fields of the provided wire.BroadcastObject are populated.

func (*Broadcast) Bitmessage

func (broadcast *Broadcast) Bitmessage() *Bitmessage

Bitmessage returns the message data.

func (*Broadcast) Object

func (broadcast *Broadcast) Object() obj.Broadcast

Object returns the object form of the message.

func (*Broadcast) String

func (broadcast *Broadcast) String() string

type Data

type Data struct {
	Key      identity.PublicKey
	Version  uint64
	Stream   uint64
	Behavior uint32
	Pow      *pow.Data
}

func (*Data) Decode

func (d *Data) Decode(r io.Reader) error

Decode reads a public identity as a publicID type, which implements Public.

func (*Data) Encode

func (d *Data) Encode(w io.Writer) error

Encode serializes the public identity.

func (*Data) PubKeyData

func (d *Data) PubKeyData() *obj.PubKeyData

type Message

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

Message is a representation of a message object that includes data which would normally be encrypted.

func NewMessage

func NewMessage(msg *obj.Message, private *identity.PrivateID) (*Message, error)

NewMessage attempts to decrypt the data in a message object and turn it into a Message.

func SignAndEncryptMessage

func SignAndEncryptMessage(expiration time.Time, streamNumber uint64,
	bm *Bitmessage, ack []byte, privID *identity.PrivateKey,
	pubID *identity.PublicKey) (*Message, error)

SignAndEncryptMessage signs and encrypts a Message, populating the Signature and Encrypted fields using the provided private identity.

The private identity supplied should be of the sender. The public identity should be that of the recipient. There are no checks against supplying invalid private or public identities.

func TryDecryptAndVerifyMessage

func TryDecryptAndVerifyMessage(msg *obj.Message, privID *identity.PrivateID) (*Message, error)

TryDecryptAndVerifyMessage tries to decrypt an obj.Message using the private identity. If it fails, it returns ErrInvalidIdentity. If decryption succeeds, it verifies the embedded signature. If signature verification fails, it returns ErrInvalidSignature. Else, it returns nil.

All necessary fields of the provided obj.Message are populated.

func (*Message) Ack

func (msg *Message) Ack() []byte

Ack returns the acknowledgement message.

func (*Message) Bitmessage

func (msg *Message) Bitmessage() *Bitmessage

Bitmessage returns the message data.

func (*Message) Object

func (msg *Message) Object() *obj.Message

Object returns the object form of the message that can be sent over the network.

type PubKeyObject

type PubKeyObject interface {
	Object() obj.Object
	Data() *obj.PubKeyData
	Behavior() uint32
	Pow() *pow.Data
	Tag() *hash.Sha
	String() string
}

PubKeyObject is an interface representing a PubKeyMessage. It represents a pubkey object that we either created or were able to decrypt. It encapsulates the cryptographic operations required to work with pubkey objects.

func GeneratePubKey

func GeneratePubKey(privID *identity.PrivateID, expiry time.Duration) (PubKeyObject, error)

GeneratePubKey generates a PubKey from the specified private identity. It also signs and encrypts it (if necessary) yielding an object that only needs proof-of-work to be done on it.

func TryDecryptAndVerifyPubKey

func TryDecryptAndVerifyPubKey(msg obj.Object, address bmutil.Address) (PubKeyObject, error)

TryDecryptAndVerifyPubKey tries to decrypt a wire.PubKeyObject of the address. If it fails, it returns ErrInvalidIdentity. If decryption succeeds, it verifies the embedded signature. If signature verification fails, it returns ErrInvalidSignature. Else, it returns nil.

All necessary fields of the provided wire.PubKeyObject are populated.

Jump to

Keyboard shortcuts

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