protocol

package
v0.0.0-...-d472a1d Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package protocol contains basic protocol functionality to encrypt, decrypt messages with plaintext and OTR protocols

Index

Constants

View Source
const (
	PlainType = "plain"
	OTRType   = "otr"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type OTRHandshakeStep

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

A type of error that indicates that the protocol is undergoing the handshake

type OTRProtocol

type OTRProtocol struct {
	Protocol
	Conv *otr.Conversation
}

An OTR protocol that contains the crypto/otr struct

func NewOTRProtocol

func NewOTRProtocol() *OTRProtocol

Create a new OTR session, with new keys and a new Conversation

func (*OTRProtocol) Decrypt

func (o *OTRProtocol) Decrypt(in []byte, onInfoReceive func(messageToDisplay string)) ([][]byte, error)

Decrypt the message and handle OTR protocol

func (*OTRProtocol) Encrypt

func (o *OTRProtocol) Encrypt(in []byte) ([][]byte, error)

Encrypt the message

func (*OTRProtocol) EndSession

func (o *OTRProtocol) EndSession()

Ends the OTR conversation

func (*OTRProtocol) GetSessionID

func (o *OTRProtocol) GetSessionID() uint64

Get the SessionID for an OTR session if it exists, or 0 if no session id exists

func (*OTRProtocol) InitFromBytes

func (o *OTRProtocol) InitFromBytes(dec []byte) error

func (*OTRProtocol) IsActive

func (o *OTRProtocol) IsActive() bool

Returns true if an active OTR session has been created and in use

func (*OTRProtocol) IsEncrypted

func (o *OTRProtocol) IsEncrypted() bool

Returns true if an OTR conversation is now encrypted

func (*OTRProtocol) NewSession

func (o *OTRProtocol) NewSession() (string, error)

Create a new session

func (*OTRProtocol) Serialize

func (o *OTRProtocol) Serialize() []byte

Serialize the private key of an OTR protocol, which is all that is needed to recreate

func (*OTRProtocol) ToType

func (o *OTRProtocol) ToType() string

Return type of protocol

type PlainProtocol

type PlainProtocol struct {
	Protocol
	SessionID uint64
	// TODO this should be private?
	ProtocolFinished bool
}

Type of protocol that just lets text pass through without applying any encryption

func (*PlainProtocol) Decrypt

func (p *PlainProtocol) Decrypt(dec []byte, onProtocolFinish func(messageToDisplay string)) ([][]byte, error)

Decrypts the message by just returning it

func (*PlainProtocol) Encrypt

func (p *PlainProtocol) Encrypt(in []byte) ([][]byte, error)

Encrypts the text by adding it into a 2D byte array

func (*PlainProtocol) EndSession

func (p *PlainProtocol) EndSession()

Ends a plain protocol session

func (*PlainProtocol) GetSessionID

func (p *PlainProtocol) GetSessionID() uint64

func (*PlainProtocol) InitFromBytes

func (p *PlainProtocol) InitFromBytes(dec []byte) error

func (*PlainProtocol) IsActive

func (p *PlainProtocol) IsActive() bool

Always returns true as a plain protocol is always active

func (*PlainProtocol) IsEncrypted

func (p *PlainProtocol) IsEncrypted() bool

Always returns false as a plain protocol is never encrypted

func (*PlainProtocol) NewSession

func (p *PlainProtocol) NewSession() (string, error)

Start a new plain protocol session

func (*PlainProtocol) Serialize

func (p *PlainProtocol) Serialize() []byte

Serialize the protocol to save in a database

func (*PlainProtocol) ToType

func (p *PlainProtocol) ToType() string

Converts plain protocol to type

type Protocol

type Protocol interface {
	InitFromBytes([]byte) error
	Encrypt(in []byte) ([][]byte, error)
	Decrypt(cypher []byte, onInfoReceive func(messageToDisplay string)) ([][]byte, error)
	IsEncrypted() bool
	IsActive() bool
	NewSession() (string, error)
	GetSessionID() uint64
	EndSession()
	Serialize() []byte
	ToType() string
}

A generic Protocol interface to handle common protocol methods

func CreateProtocolFromType

func CreateProtocolFromType(protoType string) Protocol

Given the protocol type, reconstruct the subclass Should be used in conjunction with Protocol#InitFromBytes to re-create a protocol

Jump to

Keyboard shortcuts

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