hyperlane_plugin_webhook/
const.rs1pub const ATTR_WEBHOOK_EVENT: &str = "hyperlane_plugin_webhook_event";
3
4pub const HEADER_STRIPE_SIGNATURE: &str = "stripe-signature";
6
7pub const HEADER_GITHUB_SIGNATURE_256: &str = "x-hub-signature-256";
9
10pub const HEADER_GITHUB_DELIVERY: &str = "x-github-delivery";
12
13pub const HEADER_SHOPIFY_HMAC_SHA256: &str = "x-shopify-hmac-sha256";
15
16pub const DEFAULT_TOLERANCE_SECS: u64 = 300;
18
19pub const DEFAULT_REPLAY_TTL_SECS: u64 = 600;
21
22pub const DEFAULT_REPLAY_MAX_ENTRIES: usize = 65_536;
24
25pub const DEFAULT_MAX_BODY_BYTES: usize = 2 * 1024 * 1024;
27
28pub const DEFAULT_STRIPE_VERSION: &str = "v1";
30
31pub const GITHUB_SHA256_PREFIX: &str = "sha256=";
33
34pub(crate) const REPLAY_SHARD_COUNT: usize = 64;
36
37pub(crate) const SHA256_INIT: [u32; 8] = [
39 0x6a09_e667,
40 0xbb67_ae85,
41 0x3c6e_f372,
42 0xa54f_f53a,
43 0x510e_527f,
44 0x9b05_688c,
45 0x1f83_d9ab,
46 0x5be0_cd19,
47];
48
49pub(crate) const SHA256_K: [u32; 64] = [
51 0x428a_2f98,
52 0x7137_4491,
53 0xb5c0_fbcf,
54 0xe9b5_dba5,
55 0x3956_c25b,
56 0x59f1_11f1,
57 0x923f_82a4,
58 0xab1c_5ed5,
59 0xd807_aa98,
60 0x1283_5b01,
61 0x2431_85be,
62 0x550c_7dc3,
63 0x72be_5d74,
64 0x80de_b1fe,
65 0x9bdc_06a7,
66 0xc19b_f174,
67 0xe49b_69c1,
68 0xefbe_4786,
69 0x0fc1_9dc6,
70 0x240c_a1cc,
71 0x2de9_2c6f,
72 0x4a74_84aa,
73 0x5cb0_a9dc,
74 0x76f9_88da,
75 0x983e_5152,
76 0xa831_c66d,
77 0xb003_27c8,
78 0xbf59_7fc7,
79 0xc6e0_0bf3,
80 0xd5a7_9147,
81 0x06ca_6351,
82 0x1429_2967,
83 0x27b7_0a85,
84 0x2e1b_2138,
85 0x4d2c_6dfc,
86 0x5338_0d13,
87 0x650a_7354,
88 0x766a_0abb,
89 0x81c2_c92e,
90 0x9272_2c85,
91 0xa2bf_e8a1,
92 0xa81a_664b,
93 0xc24b_8b70,
94 0xc76c_51a3,
95 0xd192_e819,
96 0xd699_0624,
97 0xf40e_3585,
98 0x106a_a070,
99 0x19a4_c116,
100 0x1e37_6c08,
101 0x2748_774c,
102 0x34b0_bcb5,
103 0x391c_0cb3,
104 0x4ed8_aa4a,
105 0x5b9c_ca4f,
106 0x682e_6ff3,
107 0x748f_82ee,
108 0x78a5_636f,
109 0x84c8_7814,
110 0x8cc7_0208,
111 0x90be_fffa,
112 0xa450_6ceb,
113 0xbef9_a3f7,
114 0xc671_78f2,
115];
116
117pub(crate) const USE_AARCH64_SHA2: bool = cfg!(all(
119 target_arch = "aarch64",
120 target_feature = "sha2",
121 target_endian = "little"
122));
123
124pub(crate) const HEX_DIGITS: &[u8; 16] = b"0123456789abcdef";
126
127pub(crate) const BASE64_ALPHABET: &[u8; 64] =
129 b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
130
131pub(crate) const REJECT_CONTENT_TYPE: &str = "text/plain; charset=utf-8";
133
134pub(crate) const BODY_UNAUTHORIZED: &[u8] = b"Invalid webhook signature";
136
137pub(crate) const BODY_REPLAY: &[u8] = b"Duplicate webhook delivery";
139
140pub(crate) const BODY_TOO_LARGE: &[u8] = b"Webhook payload too large";
142
143pub(crate) const DEBUG_REDACTED: &str = "<redacted>";
145
146pub(crate) const DEBUG_WEBHOOK_SECRET: &str = "WebhookSecret";
148
149pub(crate) const DEBUG_HMAC_KEY: &str = "HmacSha256Key";
151
152pub(crate) const REPLAY_SEPARATOR: &[u8] = &[0xFF];
154
155pub(crate) const STRIPE_TIMESTAMP_SEP: &[u8] = b".";
157
158pub(crate) const ATTR_WEBHOOK_EVENT_MAP_KEY: &str = "External(\"hyperlane_plugin_webhook_event\")";
160
161pub(crate) const STRIPE_STACK_CANDIDATES: usize = 8;
163
164pub(crate) const HMAC_OUTER_BIT_LEN_BE: [u8; 8] = 768u64.to_be_bytes();
166
167pub(crate) const HEX_ENCODE_PAIRS: [[u8; 2]; 256] = {
169 let mut table: [[u8; 2]; 256] = [[0u8; 2]; 256];
170 let mut i: usize = 0;
171 while i < 256 {
172 table[i] = [HEX_DIGITS[i >> 4], HEX_DIGITS[i & 0x0F]];
173 i += 1;
174 }
175 table
176};
177
178pub(crate) const HEX_DECODE_LUT: [u8; 256] = {
180 let mut table: [u8; 256] = [0xFFu8; 256];
181 let mut c: usize = b'0' as usize;
182 while c <= b'9' as usize {
183 table[c] = (c - b'0' as usize) as u8;
184 c += 1;
185 }
186 let mut c: usize = b'a' as usize;
187 while c <= b'f' as usize {
188 table[c] = (c - b'a' as usize + 10) as u8;
189 c += 1;
190 }
191 let mut c: usize = b'A' as usize;
192 while c <= b'F' as usize {
193 table[c] = (c - b'A' as usize + 10) as u8;
194 c += 1;
195 }
196 table
197};
198
199pub(crate) const BASE64_DECODE_LUT: [u8; 256] = {
201 let mut table: [u8; 256] = [0xFFu8; 256];
202 let mut c: usize = b'A' as usize;
203 while c <= b'Z' as usize {
204 table[c] = (c - b'A' as usize) as u8;
205 c += 1;
206 }
207 let mut c: usize = b'a' as usize;
208 while c <= b'z' as usize {
209 table[c] = (c - b'a' as usize + 26) as u8;
210 c += 1;
211 }
212 let mut c: usize = b'0' as usize;
213 while c <= b'9' as usize {
214 table[c] = (c - b'0' as usize + 52) as u8;
215 c += 1;
216 }
217 table[b'+' as usize] = 62;
218 table[b'-' as usize] = 62;
219 table[b'/' as usize] = 63;
220 table[b'_' as usize] = 63;
221 table
222};
223
224pub(crate) const BYTE_EQ: u8 = b'=';
226
227pub(crate) const BYTE_SLASH: u8 = b'/';
229
230pub(crate) const STRIPE_TIME_KEY: &str = "t";