message

package
v0.0.0-...-1550479 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package designed with functions to aid in creating, packaging, and unpackaging CipherCord messages.

Index

Constants

View Source
const EncryptionType string = "aes-256/gcm/b64r"

Advanced Encryption Standard (256-bit) / Galois/Counter Mode / Base64 (RAW)

View Source
const HashingType string = "sha-256/b64r/:32"

Secure Hash Algorithm (256-bit) / Base64 (RAW) / Cut 32

View Source
const Version = "1"

The major API version number.

Variables

View Source
var ErrTooSmall = fmt.Errorf("ciphercord: cipher text is smaller than the nonce size")

Cipher text is smaller than the nonce size.

View Source
var ErrUnmatched error = fmt.Errorf("ciphercord: one or more unmatched fields")

Not a serious error message, this usually means either the key doesn't match or the message was packaged with a different client.

Functions

func Decrypt

func Decrypt(s string, key32 string) (string, error)

Decrypts s into plain text. Argument key32 means a key of 32 characters.

func Encode

func Encode(msg EncryptedMessage) (string, error)

Encodes an EncryptedMessage into a plain text string.

func Encrypt

func Encrypt(s string, key32 string) (string, error)

Encrypts s into an encrypted string. Argument key32 means a key of 32 characters.

func Hash32

func Hash32(s string) string

Takes string and hashes it to be 32 characters. This is how the other functions convert key to key32

func Package

func Package(umsg UnencryptedMessage) (string, error)

Packages up an UnencryptedMessage to string to be ready for sending.

Types

type EncryptedMessage

type EncryptedMessage struct {
	Key        string `json:"key"`        // Hash of key32.
	Version    string `json:"version"`    // Unencrypted API version.
	Encryption string `json:"encryption"` // Unencrypted encryption type.
	Hashing    string `json:"hashing"`    // Unencrypted hashing type.
	Room       string `json:"room"`       // Unencrypted room name.
	Content    string `json:"content"`    // Encrypted message content.
	Author     string `json:"author"`     // Encrypted nickname of author.
}

A package of encrypted data that is ready to be sent out in the world.

func Decode

func Decode(s string) (EncryptedMessage, error)

Decodes a plain text string back into an EncryptedMessage.

func EncryptMessage

func EncryptMessage(umsg UnencryptedMessage) (EncryptedMessage, error)

Converts an UnencryptedMessage into an EncryptedMessage.

type UnencryptedMessage

type UnencryptedMessage struct {
	Key     string // Secret password in plain text
	Room    string // Room name
	Content string // Message content
	Author  string // Author's nickname

	Version string // *API version number
}

UnencryptedMessage represents a package of unencrypted information that will later be encrypted. Nothing in this struct will ever be sent over the wire.

The * indicates that this field has a preassigned value at the packaging step. It is only useful after decryption.

func DecryptMessage

func DecryptMessage(emsg EncryptedMessage, key string) (UnencryptedMessage, error)

Converts an EncryptedMessage into an UnencryptedMessage.

func DecryptMessageUnstable

func DecryptMessageUnstable(emsg EncryptedMessage, key string) (UnencryptedMessage, error)

The same as DecryptMessage but it assumes everything matches up. It doesn't check to see if encryption types, hashing types, or keys match up. Will not return ErrUnmatched.

func Unpackage

func Unpackage(s string, key string) (UnencryptedMessage, error)

Unpackages a string to UnencryptedMessage be ready for parsing.

Jump to

Keyboard shortcuts

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