-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
128 lines (105 loc) · 3.68 KB
/
error.rs
File metadata and controls
128 lines (105 loc) · 3.68 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
use binary_codec::{FromBytes, ToBytes};
use serde::{Deserialize, Serialize};
use crate::scripting::opcode_script::ScriptError;
/// Plabble error code body
/// The length is prefixed by a u8 in the packet body.
#[derive(FromBytes, ToBytes, Serialize, Deserialize, Debug, PartialEq, Clone)]
#[cfg_attr(feature = "ffi", derive(uniffi::Error))]
#[serde(tag = "type")]
#[repr(u8)]
pub enum PlabbleError {
/* 0 = no error, but it is NOT used */
/* generic errors: 1-10 */
/// The requested protocol version is not supported by this implementation.
/// Contains the min and max version the server supports.
UnsupportedVersion { min_version: u8, max_version: u8 } = 1,
/// The requested algorithm in crypto settings is not supported by the server
UnsupportedAlgorithm {
#[dyn_length]
name: String,
} = 2,
/// The requested CUSTOM packet type is not supported by the server
UnsupportedSubProtocol = 3,
/// The request is not valid
InvalidRequest = 4,
/* bucket errors: 10-100 */
/// Bucket by ID not found (or existence denied)
BucketNotFound = 10,
/// Bucket with that ID already exists
BucketAlreadyExists = 11,
/* certificate errors: 110-115 */
/// Certificate by ID not found
CertificateNotFound = 110,
/// Requested certificate is not valid (according to server)
CertificateInvalid = 111,
// ...
/// OPCODE script execution error
OpcodeScriptError(ScriptError) = 210,
/// Internal server error / unknown error
InternalServerError = 255,
}
#[cfg(test)]
mod tests {
use binary_codec::{BinaryDeserializer, BinarySerializer};
use crate::packets::response::PlabbleResponsePacket;
#[test]
fn can_serialize_and_deserialize_unsupported_version_error_response() {
let response: PlabbleResponsePacket = toml::from_str(
r#"
version = 1
use_encryption = true
[header]
packet_type = "Error"
request_counter = 1
[body]
type = "UnsupportedVersion"
min_version = 1
max_version = 3
"#,
)
.unwrap();
let serialized = response.to_bytes(None).unwrap();
let deserialized = PlabbleResponsePacket::from_bytes(&serialized, None).unwrap();
// Version = 0001, flags = 0100 Packet type: 15 = 1111, flags = 0000. Counter = 01, Error type = 1, min version = 1, max version = 3
assert_eq!(vec![0b0100_0001, 0b0000_1111, 0, 1, 1, 1, 3], serialized);
assert_eq!(response, deserialized);
}
#[test]
fn can_serialize_and_deserialize_unsupported_algorithm_error_response() {
let response: PlabbleResponsePacket = toml::from_str(
r#"
version = 1
use_encryption = true
[header]
packet_type = "Error"
request_counter = 1
[body]
type = "UnsupportedAlgorithm"
name = "Ed25519"
"#,
)
.unwrap();
let serialized = response.to_bytes(None).unwrap();
let deserialized = PlabbleResponsePacket::from_bytes(&serialized, None).unwrap();
// Version = 0001, flags = 0100 Packet type: 15 = 1111, flags = 0000. Counter = 01, Error type = 2, name length = 7, name = "Ed25519"
assert_eq!(
vec![
0b0100_0001,
0b0000_1111,
0,
1,
2,
7,
b'E',
b'd',
b'2',
b'5',
b'5',
b'1',
b'9'
],
serialized
);
assert_eq!(response, deserialized);
}
}