Documentation
¶
Index ¶
- func DecryptMessage(sessionKey *SessionKey, encrypted *EncryptedMessage) ([]byte, error)
- func GetKeyID(publicKey []byte) string
- func ValidateKeyPair(keypair *KeyPair) error
- type EncryptedMessage
- type FileMeta
- type Handshake
- type KeyPair
- type Message
- type MessageType
- type PublicKeyInfo
- type SessionKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecryptMessage ¶
func DecryptMessage(sessionKey *SessionKey, encrypted *EncryptedMessage) ([]byte, error)
DecryptMessage decrypts a message using ChaCha20-Poly1305
func ValidateKeyPair ¶
ValidateKeyPair validates a keypair
Types ¶
type EncryptedMessage ¶
type EncryptedMessage struct { Type MessageType `json:"type"` Sender string `json:"sender"` CreatedAt time.Time `json:"created_at"` Content string `json:"content,omitempty"` // Plaintext for system messages Encrypted []byte `json:"encrypted,omitempty"` // Encrypted payload Nonce []byte `json:"nonce,omitempty"` // For encrypted messages Recipient string `json:"recipient,omitempty"` // For direct messages IsEncrypted bool `json:"is_encrypted,omitempty"` // Flag for encrypted messages File *FileMeta `json:"file,omitempty"` // For file messages }
EncryptedMessage represents an E2E encrypted message
func EncryptMessage ¶
func EncryptMessage(sessionKey *SessionKey, plaintext []byte) (*EncryptedMessage, error)
EncryptMessage encrypts a message using ChaCha20-Poly1305
func EncryptTextMessage ¶
func EncryptTextMessage(sessionKey *SessionKey, sender, content string) (*EncryptedMessage, error)
EncryptTextMessage encrypts a text message
type Handshake ¶
type Handshake struct { Username string `json:"username"` Admin bool `json:"admin"` AdminKey string `json:"admin_key,omitempty"` }
Handshake is sent by the client on WebSocket connect for authentication Admin key is only sent if admin is true Username is always sent (case-insensitive match on server)
type KeyPair ¶
type KeyPair struct { PublicKey []byte `json:"public_key"` PrivateKey []byte `json:"private_key"` CreatedAt time.Time `json:"created_at"` }
KeyPair represents a user's cryptographic identity
func GenerateKeyPair ¶
GenerateKeyPair creates a new X25519 keypair
type Message ¶
type Message struct { Sender string `json:"sender"` Content string `json:"content"` CreatedAt time.Time `json:"created_at"` Type MessageType `json:"type,omitempty"` // For file messages, Content is empty and File is set File *FileMeta `json:"file,omitempty"` }
func DecryptTextMessage ¶
func DecryptTextMessage(sessionKey *SessionKey, encrypted *EncryptedMessage) (*Message, error)
DecryptTextMessage decrypts a text message and returns the original Message
type MessageType ¶
type MessageType string
MessageType distinguishes between text and file messages (add more types as needed)
const ( TextMessage MessageType = "text" FileMessageType MessageType = "file" )
type PublicKeyInfo ¶
type PublicKeyInfo struct { Username string `json:"username"` PublicKey []byte `json:"public_key"` CreatedAt time.Time `json:"created_at"` KeyID string `json:"key_id"` // SHA256 hash of public key }
PublicKeyInfo represents a user's public key for distribution
type SessionKey ¶
type SessionKey struct { Key []byte `json:"key"` CreatedAt time.Time `json:"created_at"` KeyID string `json:"key_id"` }
SessionKey represents a derived session key for a conversation
func DeriveSessionKey ¶
func DeriveSessionKey(myPrivateKey, theirPublicKey []byte, conversationID string) (*SessionKey, error)
DeriveSessionKey creates a shared secret between two users