blob: c5b7bcbfbff54d792ddf5f9940c17109d9d93102 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright (c) 2024 Sumner Evans
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package olm
import "maunium.net/go/mautrix/id"
type OutboundGroupSession interface {
// Pickle returns a Session as a base64 string. Encrypts the Session using
// the supplied key.
Pickle(key []byte) ([]byte, error)
// Unpickle loads an [OutboundGroupSession] from a pickled base64 string.
// Decrypts the [OutboundGroupSession] using the supplied key.
Unpickle(pickled, key []byte) error
// Encrypt encrypts a message using the [OutboundGroupSession]. Returns the
// encrypted message as base64.
Encrypt(plaintext []byte) ([]byte, error)
// ID returns a base64-encoded identifier for this session.
ID() id.SessionID
// MessageIndex returns the message index for this session. Each message
// is sent with an increasing index; this returns the index for the next
// message.
MessageIndex() uint
// Key returns the base64-encoded current ratchet key for this session.
Key() string
}
var InitNewOutboundGroupSessionFromPickled func(pickled, key []byte) (OutboundGroupSession, error)
var InitNewOutboundGroupSession func() OutboundGroupSession
var InitNewBlankOutboundGroupSession func() OutboundGroupSession
// OutboundGroupSessionFromPickled loads an OutboundGroupSession from a pickled
// base64 string. Decrypts the OutboundGroupSession using the supplied key.
// Returns error on failure. If the key doesn't match the one used to encrypt
// the OutboundGroupSession then the error will be "BAD_SESSION_KEY". If the
// base64 couldn't be decoded then the error will be "INVALID_BASE64".
func OutboundGroupSessionFromPickled(pickled, key []byte) (OutboundGroupSession, error) {
return InitNewOutboundGroupSessionFromPickled(pickled, key)
}
// NewOutboundGroupSession creates a new outbound group session.
func NewOutboundGroupSession() OutboundGroupSession {
return InitNewOutboundGroupSession()
}
// NewBlankOutboundGroupSession initialises an empty [OutboundGroupSession].
func NewBlankOutboundGroupSession() OutboundGroupSession {
return InitNewBlankOutboundGroupSession()
}
|