Documentation ¶
Overview ¶
Package protocol contains basic protocol functionality to encrypt, decrypt messages with plaintext and OTR protocols
Index ¶
- Constants
- type OTRHandshakeStep
- type OTRProtocol
- func (o *OTRProtocol) Decrypt(in []byte, onInfoReceive func(messageToDisplay string)) ([][]byte, error)
- func (o *OTRProtocol) Encrypt(in []byte) ([][]byte, error)
- func (o *OTRProtocol) EndSession()
- func (o *OTRProtocol) GetSessionID() uint64
- func (o *OTRProtocol) InitFromBytes(dec []byte) error
- func (o *OTRProtocol) IsActive() bool
- func (o *OTRProtocol) IsEncrypted() bool
- func (o *OTRProtocol) NewSession() (string, error)
- func (o *OTRProtocol) Serialize() []byte
- func (o *OTRProtocol) ToType() string
- type PlainProtocol
- func (p *PlainProtocol) Decrypt(dec []byte, onProtocolFinish func(messageToDisplay string)) ([][]byte, error)
- func (p *PlainProtocol) Encrypt(in []byte) ([][]byte, error)
- func (p *PlainProtocol) EndSession()
- func (p *PlainProtocol) GetSessionID() uint64
- func (p *PlainProtocol) InitFromBytes(dec []byte) error
- func (p *PlainProtocol) IsActive() bool
- func (p *PlainProtocol) IsEncrypted() bool
- func (p *PlainProtocol) NewSession() (string, error)
- func (p *PlainProtocol) Serialize() []byte
- func (p *PlainProtocol) ToType() string
- type Protocol
Constants ¶
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) 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
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 ¶
Given the protocol type, reconstruct the subclass Should be used in conjunction with Protocol#InitFromBytes to re-create a protocol