oxedyne/fe2o3/fe2o3_shield/src/srv/msg/syntax.rs
7.2 KiB, 79 runs
created by r1870400018:882, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | use crate::srv::{ |
| 2 | constant, |
| 3 | }; |
| 4 | |
| 5 | use oxedyne_fe2o3_core::{ |
| 6 | prelude::*, |
| 7 | //mem::Extract, |
| 8 | }; |
| 9 | use oxedyne_fe2o3_jdat::prelude::*; |
| 10 | use oxedyne_fe2o3_syntax::{ |
| 11 | arg::{ |
| 12 | Arg, |
| 13 | ArgConfig, |
| 14 | }, |
| 15 | cmd::{ |
| 16 | Cmd, |
| 17 | CmdConfig, |
| 18 | }, |
| 19 | core::{ |
| 20 | Syntax, |
| 21 | SyntaxRef, |
| 22 | SyntaxConfig, |
| 23 | }, |
| 24 | }; |
| 25 | |
| 26 | |
| 27 | pub fn base_msg() -> Outcome<SyntaxRef> { |
| 28 | |
| 29 | let mut s = Syntax::from(SyntaxConfig { |
| 30 | name: fmt!("Shield Protocol"), |
| 31 | ver: constant::VERSION.clone(), |
| 32 | about: Some(fmt!("Signed Hash In Every Little Datagram (SHIELD)")), |
| 33 | ..Default::default() |
| 34 | }); |
| 35 | |
| 36 | // Reusable components ==================================================== |
| 37 | // |
| 38 | //let arg_uid = Arg::from(ArgConfig { |
| 39 | // name: fmt!("IdDat"), |
| 40 | // hyph1: Some(fmt!("u")), |
| 41 | // hyph2: Some(fmt!("uid")), |
| 42 | // evals: vec![UID::KIND], |
| 43 | // help: Some(fmt!("User identifier (unsigned int)")), |
| 44 | // ..Default::default() |
| 45 | //}); |
| 46 | let arg_sid = Arg::from(ArgConfig { |
| 47 | name: fmt!("IdDat"), |
| 48 | hyph1: Some(fmt!("s")), |
| 49 | hyph2: Some(fmt!("sid")), |
| 50 | vals: vec![(constant::SESSION_ID_KIND, fmt!("Id (unsigned int)")).into()], |
| 51 | help: Some(fmt!("Session identifier")), |
| 52 | ..Default::default() |
| 53 | }); |
| 54 | //let arg_pow_code = Arg::from(ArgConfig { |
| 55 | // name: fmt!("PowCode"), |
| 56 | // hyph1: Some(fmt!("pc")), |
| 57 | // hyph2: Some(fmt!("pow-code")), |
| 58 | // evals: vec![Kind::BC64], |
| 59 | // help: Some(fmt!("Use this proof of work code for packets")), |
| 60 | // ..Default::default() |
| 61 | //}); |
| 62 | let arg_pow_zbits = Arg::from(ArgConfig { |
| 63 | name: fmt!("PowZeroBits"), |
| 64 | hyph1: Some(fmt!("zb")), |
| 65 | hyph2: Some(fmt!("zero-bits")), |
| 66 | vals: vec![(Kind::U16, fmt!("Number of zero bits (u16)")).into()], |
| 67 | help: Some(fmt!("Number of zero bits to use for proof of work")), |
| 68 | ..Default::default() |
| 69 | }); |
| 70 | //let arg_my_pack_sign_pk = Arg::from(ArgConfig { |
| 71 | // name: fmt!("MyPacketPublicSigningKey"), |
| 72 | // hyph1: Some(fmt!("mpsp")), |
| 73 | // hyph2: Some(fmt!("my-pack-sign-pk")), |
| 74 | // evals: vec![Kind::BC64], |
| 75 | // help: Some(fmt!("My packet public signing key")), |
| 76 | // ..Default::default() |
| 77 | //}); |
| 78 | let arg_your_pack_sign_pk = Arg::from(ArgConfig { |
| 79 | name: fmt!("YourPacketPublicSigningKey"), |
| 80 | hyph1: Some(fmt!("yppsk")), |
| 81 | hyph2: Some(fmt!("your-pack-sign-pk")), |
| 82 | vals: vec![(Kind::BC64, fmt!("Public key")).into()], |
| 83 | help: Some(fmt!("Your packet public signing key")), |
| 84 | ..Default::default() |
| 85 | }); |
| 86 | //let arg_my_msg_sign_pk = Arg::from(ArgConfig { |
| 87 | // name: fmt!("MyMessagePublicSigningKey"), |
| 88 | // hyph1: Some(fmt!("mmsp")), |
| 89 | // hyph2: Some(fmt!("my-msg-sign-pk")), |
| 90 | // evals: vec![Kind::BC64], |
| 91 | // help: Some(fmt!("My message public signing key")), |
| 92 | // ..Default::default() |
| 93 | //}); |
| 94 | //let arg_your_msg_sign_pk = Arg::from(ArgConfig { |
| 95 | // name: fmt!("YourMessagePublicSigningKey"), |
| 96 | // hyph1: Some(fmt!("ymsp")), |
| 97 | // hyph2: Some(fmt!("your-msg-sign-pk")), |
| 98 | // evals: vec![Kind::BC64], |
| 99 | // help: Some(fmt!("Your message public signing key")), |
| 100 | // ..Default::default() |
| 101 | //}); |
| 102 | //let arg_sign = Arg::from(ArgConfig { |
| 103 | // name: fmt!("Signature"), |
| 104 | // hyph1: Some(fmt!("sig")), |
| 105 | // hyph2: Some(fmt!("signature")), |
| 106 | // evals: vec![Kind::BC64], |
| 107 | // help: Some(fmt!("Signature applied to message contents")), |
| 108 | // ..Default::default() |
| 109 | //}); |
| 110 | |
| 111 | // Message arguments ====================================================== |
| 112 | // |
| 113 | //s = res!(s.add_arg(arg_uid.clone().required(true))); |
| 114 | //s = res!(s.add_arg(arg_pow_zbits.clone().required(true))); |
| 115 | //s = res!(s.add_arg(arg_pow_code.clone().required(true))); |
| 116 | s = res!(s.add_arg(arg_sid.clone().required(false))); |
| 117 | s = res!(s.add_arg(arg_pow_zbits.clone().required(true))); |
| 118 | |
| 119 | // HReq1 ================================================================== |
| 120 | // |
| 121 | let mut c = Cmd::from(CmdConfig { |
| 122 | name: fmt!("hreq1"), |
| 123 | help: Some(fmt!("Initial handshake request")), |
| 124 | ..Default::default() |
| 125 | }); |
| 126 | c = res!(c.add_arg(arg_your_pack_sign_pk.clone())); // My version of your signature public key. |
| 127 | s = res!(s.add_cmd(c)); |
| 128 | |
| 129 | // HResp1 ================================================================= |
| 130 | // |
| 131 | let mut c = Cmd::from(CmdConfig { |
| 132 | name: fmt!("hresp1"), |
| 133 | help: Some(fmt!("Initial handshake response")), |
| 134 | ..Default::default() |
| 135 | }); |
| 136 | //let arg_send_sign_pk = Arg::from(ArgConfig { |
| 137 | // name: fmt!("SendPublicSigningKey"), |
| 138 | // hyph1: Some(fmt!("sspk")), |
| 139 | // hyph2: Some(fmt!("send-sign-pk")), |
| 140 | // help: Some(fmt!("Send signing public key")), |
| 141 | // ..Default::default() |
| 142 | //}); |
| 143 | c = res!(c.add_arg(arg_pow_zbits.clone().required(true))); |
| 144 | c = res!(c.add_arg(arg_your_pack_sign_pk)); // My version of your signature public key. |
| 145 | s = res!(s.add_cmd(c)); |
| 146 | |
| 147 | // HReq2 ================================================================== |
| 148 | // |
| 149 | let c = Cmd::from(CmdConfig { |
| 150 | name: fmt!("hreq2"), |
| 151 | help: Some(fmt!("Second handshake request")), |
| 152 | ..Default::default() |
| 153 | }); |
| 154 | //c = res!(c.add_arg(arg_sign_pk.clone().required(false))); |
| 155 | //c = res!(c.add_arg(arg_sign.clone().required(true))); |
| 156 | s = res!(s.add_cmd(c)); |
| 157 | |
| 158 | // HResp2 ================================================================= |
| 159 | // |
| 160 | let mut c = Cmd::from(CmdConfig { |
| 161 | name: fmt!("hresp2"), |
| 162 | help: Some(fmt!("Second handshake response")), |
| 163 | ..Default::default() |
| 164 | }); |
| 165 | let arg_skey_enc = Arg::from(ArgConfig { |
| 166 | name: fmt!("EncSymKey"), |
| 167 | hyph1: Some(fmt!("sk")), |
| 168 | hyph2: Some(fmt!("sym-key")), |
| 169 | vals: vec![(Kind::BC64, fmt!("Private key")).into()], |
| 170 | help: Some(fmt!("Encrypted symmetric encryption key for session")), |
| 171 | ..Default::default() |
| 172 | }); |
| 173 | c = res!(c.add_arg(arg_skey_enc.required(true))); |
| 174 | s = res!(s.add_cmd(c)); |
| 175 | |
| 176 | // Application payload ==================================================== |
| 177 | // |
| 178 | // The one pair of commands the protocol carries without reading: a |
| 179 | // caller's bytes out, and a caller's bytes back under the same message |
| 180 | // identifier. |
| 181 | let arg_payload = Arg::from(ArgConfig { |
| 182 | name: fmt!("Payload"), |
| 183 | hyph1: Some(fmt!("p")), |
| 184 | hyph2: Some(fmt!("payload")), |
| 185 | vals: vec![(Kind::BU64, fmt!("Opaque application bytes")).into()], |
| 186 | help: Some(fmt!("Application payload, which the protocol does not read")), |
| 187 | ..Default::default() |
| 188 | }); |
| 189 | |
| 190 | let mut c = Cmd::from(CmdConfig { |
| 191 | name: fmt!("{}", constant::MSG_CMD_APP_REQUEST), |
| 192 | help: Some(fmt!("Application payload sent to a peer")), |
| 193 | ..Default::default() |
| 194 | }); |
| 195 | c = res!(c.add_arg(arg_payload.clone().required(true))); |
| 196 | s = res!(s.add_cmd(c)); |
| 197 | |
| 198 | let mut c = Cmd::from(CmdConfig { |
| 199 | name: fmt!("{}", constant::MSG_CMD_APP_REPLY), |
| 200 | help: Some(fmt!("Answer to an application payload")), |
| 201 | ..Default::default() |
| 202 | }); |
| 203 | c = res!(c.add_arg(arg_payload.required(true))); |
| 204 | s = res!(s.add_cmd(c)); |
| 205 | |
| 206 | Ok(SyntaxRef::new(s)) |
| 207 | } |