1
1
//
2
- // Copyright 2020 Signal Messenger, LLC.
2
+ // Copyright 2020-2021 Signal Messenger, LLC.
3
3
// SPDX-License-Identifier: AGPL-3.0-only
4
4
//
5
5
6
6
use crate :: curve:: KeyType ;
7
7
8
+ use displaydoc:: Display ;
9
+
8
10
use std:: error:: Error ;
9
- use std:: fmt;
10
11
use std:: panic:: UnwindSafe ;
11
12
12
13
pub type Result < T > = std:: result:: Result < T , SignalProtocolError > ;
13
14
14
- #[ derive( Debug ) ]
15
+ #[ derive( Debug , Display ) ]
15
16
pub enum SignalProtocolError {
17
+ /// invalid argument: {0}
16
18
InvalidArgument ( String ) ,
19
+ /// invalid state for call to {0} to succeed: {1}
17
20
InvalidState ( & ' static str , String ) ,
18
21
22
+ /// failed to decode protobuf: {0}
19
23
ProtobufDecodingError ( prost:: DecodeError ) ,
24
+ /// failed to encode protobuf: {0}
20
25
ProtobufEncodingError ( prost:: EncodeError ) ,
26
+ /// protobuf encoding was invalid
21
27
InvalidProtobufEncoding ,
22
28
29
+ /// ciphertext serialized bytes were too short <{0}>
23
30
CiphertextMessageTooShort ( usize ) ,
31
+ /// ciphertext version was too old <{0}>
24
32
LegacyCiphertextVersion ( u8 ) ,
33
+ /// ciphertext version was unrecognized <{0}>
25
34
UnrecognizedCiphertextVersion ( u8 ) ,
35
+ /// unrecognized message version <{0}>
26
36
UnrecognizedMessageVersion ( u32 ) ,
27
37
38
+ /// fingerprint identifiers do not match
28
39
FingerprintIdentifierMismatch ,
40
+ /// fingerprint version number mismatch them {0} us {1}
29
41
FingerprintVersionMismatch ( u32 , u32 ) ,
42
+ /// fingerprint parsing error
30
43
FingerprintParsingError ,
31
44
45
+ /// no key type identifier
32
46
NoKeyTypeIdentifier ,
47
+ /// bad key type <{0:#04x}>
33
48
BadKeyType ( u8 ) ,
49
+ /// bad key length <{1}> for key with type <{0}>
34
50
BadKeyLength ( KeyType , usize ) ,
35
51
52
+ /// invalid signature detected
36
53
SignatureValidationFailed ,
37
54
55
+ /// untrusted identity for address {0}
38
56
UntrustedIdentity ( crate :: ProtocolAddress ) ,
39
57
58
+ /// invalid prekey identifier
40
59
InvalidPreKeyId ,
60
+ /// invalid signed prekey identifier
41
61
InvalidSignedPreKeyId ,
42
62
63
+ /// invalid root key length <{0}>
43
64
InvalidRootKeyLength ( usize ) ,
65
+ /// invalid chain key length <{0}>
44
66
InvalidChainKeyLength ( usize ) ,
45
67
68
+ /// invalid MAC key length <{0}>
46
69
InvalidMacKeyLength ( usize ) ,
70
+ /// invalid cipher key length <{0}> or nonce length <{1}>
47
71
InvalidCipherCryptographicParameters ( usize , usize ) ,
72
+ /// invalid ciphertext message
48
73
InvalidCiphertext ,
49
74
75
+ /// no sender key state
50
76
NoSenderKeyState ,
51
77
78
+ /// session with '{0}' not found
52
79
SessionNotFound ( String ) ,
80
+ /// invalid session structure
53
81
InvalidSessionStructure ,
82
+ /// session for {0} has invalid registration ID {1:X}
54
83
InvalidRegistrationId ( crate :: ProtocolAddress , u32 ) ,
55
84
85
+ /// message with old counter {0} / {1}
56
86
DuplicatedMessage ( u32 , u32 ) ,
87
+ /// invalid message {0}
57
88
InvalidMessage ( & ' static str ) ,
89
+ /// internal error {0}
58
90
InternalError ( & ' static str ) ,
91
+ /// error while invoking an ffi callback: {0}
59
92
FfiBindingError ( String ) ,
93
+ /// error in method call '{0}': {1}
60
94
ApplicationCallbackError (
61
95
& ' static str ,
62
- Box < dyn Error + Send + Sync + UnwindSafe + ' static > ,
96
+ Box < dyn std :: error :: Error + Send + Sync + UnwindSafe + ' static > ,
63
97
) ,
64
98
99
+ /// invalid sealed sender message {0}
65
100
InvalidSealedSenderMessage ( String ) ,
101
+ /// unknown sealed sender message version {0}
66
102
UnknownSealedSenderVersion ( u8 ) ,
103
+ /// self send of a sealed sender message
67
104
SealedSenderSelfSend ,
68
105
}
69
106
@@ -89,110 +126,3 @@ impl From<prost::EncodeError> for SignalProtocolError {
89
126
SignalProtocolError :: ProtobufEncodingError ( value)
90
127
}
91
128
}
92
-
93
- impl fmt:: Display for SignalProtocolError {
94
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
95
- match self {
96
- SignalProtocolError :: ProtobufDecodingError ( e) => {
97
- write ! ( f, "failed to decode protobuf: {}" , e)
98
- }
99
- SignalProtocolError :: ProtobufEncodingError ( e) => {
100
- write ! ( f, "failed to encode protobuf: {}" , e)
101
- }
102
- SignalProtocolError :: InvalidProtobufEncoding => {
103
- write ! ( f, "protobuf encoding was invalid" )
104
- }
105
- SignalProtocolError :: InvalidArgument ( s) => write ! ( f, "invalid argument: {}" , s) ,
106
- SignalProtocolError :: InvalidState ( func, s) => {
107
- write ! ( f, "invalid state for call to {} to succeed: {}" , func, s)
108
- }
109
- SignalProtocolError :: CiphertextMessageTooShort ( size) => {
110
- write ! ( f, "ciphertext serialized bytes were too short <{}>" , size)
111
- }
112
- SignalProtocolError :: LegacyCiphertextVersion ( version) => {
113
- write ! ( f, "ciphertext version was too old <{}>" , version)
114
- }
115
- SignalProtocolError :: UnrecognizedCiphertextVersion ( version) => {
116
- write ! ( f, "ciphertext version was unrecognized <{}>" , version)
117
- }
118
- SignalProtocolError :: UnrecognizedMessageVersion ( message_version) => {
119
- write ! ( f, "unrecognized message version <{}>" , message_version)
120
- }
121
- SignalProtocolError :: FingerprintIdentifierMismatch => {
122
- write ! ( f, "fingerprint identifiers do not match" )
123
- }
124
- SignalProtocolError :: FingerprintVersionMismatch ( theirs, ours) => {
125
- write ! (
126
- f,
127
- "fingerprint version number mismatch them {} us {}" ,
128
- theirs, ours
129
- )
130
- }
131
- SignalProtocolError :: FingerprintParsingError => {
132
- write ! ( f, "fingerprint parsing error" )
133
- }
134
- SignalProtocolError :: NoKeyTypeIdentifier => write ! ( f, "no key type identifier" ) ,
135
- SignalProtocolError :: BadKeyType ( t) => write ! ( f, "bad key type <{:#04x}>" , t) ,
136
- SignalProtocolError :: BadKeyLength ( t, l) => {
137
- write ! ( f, "bad key length <{}> for key with type <{}>" , l, t)
138
- }
139
- SignalProtocolError :: InvalidPreKeyId => write ! ( f, "invalid prekey identifier" ) ,
140
- SignalProtocolError :: InvalidSignedPreKeyId => {
141
- write ! ( f, "invalid signed prekey identifier" )
142
- }
143
- SignalProtocolError :: InvalidChainKeyLength ( l) => {
144
- write ! ( f, "invalid chain key length <{}>" , l)
145
- }
146
- SignalProtocolError :: InvalidRootKeyLength ( l) => {
147
- write ! ( f, "invalid root key length <{}>" , l)
148
- }
149
- SignalProtocolError :: InvalidCipherCryptographicParameters ( kl, nl) => write ! (
150
- f,
151
- "invalid cipher key length <{}> or nonce length <{}>" ,
152
- kl, nl
153
- ) ,
154
- SignalProtocolError :: InvalidMacKeyLength ( l) => {
155
- write ! ( f, "invalid MAC key length <{}>" , l)
156
- }
157
- SignalProtocolError :: UntrustedIdentity ( addr) => {
158
- write ! ( f, "untrusted identity for address {}" , addr)
159
- }
160
- SignalProtocolError :: SignatureValidationFailed => {
161
- write ! ( f, "invalid signature detected" )
162
- }
163
- SignalProtocolError :: InvalidCiphertext => write ! ( f, "invalid ciphertext message" ) ,
164
- SignalProtocolError :: SessionNotFound ( who) => {
165
- write ! ( f, "session with '{}' not found" , who)
166
- }
167
- SignalProtocolError :: InvalidSessionStructure => write ! ( f, "invalid session structure" ) ,
168
- SignalProtocolError :: InvalidRegistrationId ( addr, value) => {
169
- write ! (
170
- f,
171
- "session for {} has invalid registration ID {:X}" ,
172
- addr, value
173
- )
174
- }
175
- SignalProtocolError :: DuplicatedMessage ( i, c) => {
176
- write ! ( f, "message with old counter {} / {}" , i, c)
177
- }
178
- SignalProtocolError :: InvalidMessage ( m) => write ! ( f, "invalid message {}" , m) ,
179
- SignalProtocolError :: InternalError ( m) => write ! ( f, "internal error {}" , m) ,
180
- SignalProtocolError :: NoSenderKeyState => write ! ( f, "no sender key state" ) ,
181
- SignalProtocolError :: FfiBindingError ( m) => {
182
- write ! ( f, "error while invoking an ffi callback: {}" , m)
183
- }
184
- SignalProtocolError :: ApplicationCallbackError ( func, c) => {
185
- write ! ( f, "application callback {} failed with {}" , func, c)
186
- }
187
- SignalProtocolError :: InvalidSealedSenderMessage ( m) => {
188
- write ! ( f, "invalid sealed sender message {}" , m)
189
- }
190
- SignalProtocolError :: UnknownSealedSenderVersion ( v) => {
191
- write ! ( f, "unknown sealed sender message version {}" , v)
192
- }
193
- SignalProtocolError :: SealedSenderSelfSend => {
194
- write ! ( f, "self send of a sealed sender message" )
195
- }
196
- }
197
- }
198
- }
0 commit comments