mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 09:28:11 +00:00
xs idx
This commit is contained in:
1 parent
f294f71fdb
commit
fb8422ce5f
6 files changed
+75
-2
No files matched your search
@@ -41,6 +41,9 @@ pub enum GrokClientError {
|
||||
/// Our script logic is out of date
|
||||
ScriptLogicOutOfDate,
|
||||
|
||||
/// Signature algorithm isn't working with inputs
|
||||
BadSignatureInputs,
|
||||
|
||||
// /// An error reading the file for upload.
|
||||
// FileForUploadReadError(std::io::Error),
|
||||
//
|
||||
@@ -95,6 +98,7 @@ impl Display for GrokClientError {
|
||||
Self::FailedToDecodeVerificationToken(err) => write!(f, "Failed to decode verification token: {}", err),
|
||||
Self::InvalidVerificationTokenBytes => write!(f, "Invalid verification token bytes"),
|
||||
Self::ScriptLogicOutOfDate => write!(f, "Script logic out of date"),
|
||||
Self::BadSignatureInputs => write!(f, "Bad signature inputs"),
|
||||
|
||||
//Self::FileForUploadReadError(err) => write!(f, "Error reading file for upload: {}", err),
|
||||
//Self::FileForUploadHasInvalidPath => write!(f, "The file path provided for upload is invalid."),
|
||||
|
||||
@@ -3,4 +3,5 @@ pub mod get_index_page;
|
||||
pub mod get_index_page_and_scripts;
|
||||
pub mod get_numbers;
|
||||
pub mod index_parsers;
|
||||
pub mod signature;
|
||||
pub mod utils;
|
||||
+1
-1
@@ -83,7 +83,7 @@ pub fn generate_sign(args: GenerateSignArgs<'_>) -> Result<(), GrokClientError>
|
||||
mod tests {
|
||||
use errors::AnyhowResult;
|
||||
use crate::requests::index_page::index_parsers::parse_index_verification_token::VerificationToken;
|
||||
use crate::requests::index_page::utils::generate_sign_for_new_conversation::{generate_sign, GenerateSignArgs};
|
||||
use crate::requests::index_page::signature::generate_sign_for_new_conversation::{generate_sign, GenerateSignArgs};
|
||||
|
||||
#[test]
|
||||
fn test() -> AnyhowResult<()> {
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod signature_xs;
|
||||
pub mod generate_sign_for_new_conversation;
|
||||
@@ -0,0 +1,67 @@
|
||||
use crate::error::grok_client_error::GrokClientError;
|
||||
|
||||
/*
|
||||
@staticmethod
|
||||
def xs(x_bytes: bytes, svg: str, x_values: list) -> str:
|
||||
arr = list(x_bytes) -- we already have this
|
||||
idx = arr[x_values[0]] % 16
|
||||
c = ((arr[x_values[1]] % 16) * (arr[x_values[2]] % 16)) * (arr[x_values[3]] % 16)
|
||||
o = Signature.xa(svg)
|
||||
vals = o[idx]
|
||||
k = Signature.simulateStyle(vals, c)
|
||||
|
||||
concat = str(k["color"]) + str(k["transform"])
|
||||
matches = findall(r"[\d\.\-]+", concat)
|
||||
converted = []
|
||||
for m in matches:
|
||||
num = float(m)
|
||||
hexstr = Signature.tohex(num)
|
||||
converted.append(hexstr)
|
||||
joined = "".join(converted)
|
||||
cleaned = joined.replace(".", "").replace("-", "")
|
||||
return cleaned
|
||||
*/
|
||||
|
||||
/// `bytes` is
|
||||
/// `svg_data` is the <path d="" /> svg path stroke data
|
||||
/// `x_values` are the magic numbers from the script
|
||||
pub fn signature_xs(x_bytes: &[u8], svg_data: &str, x_values: &[u8]) -> Result<String, GrokClientError> {
|
||||
/*
|
||||
Inputs:
|
||||
> xs.x_bytes = b'\xca\xddz\th\x94#\x8d\xac\xef\x01\x86x\xcc\\tB\x13\xdah\x8f\x17\x93\xd58fE\xd4\x97\x1a{\xb2\xbb\x1c\xc4+-\xe28E6.~g_\x04\x86T'
|
||||
> xs.svg = M 10,30 C 147,16 51,222 136,87 h 31 s 177,77 40,114 C 68,166 18,188 114,44 h 220 s 148,210 202,25 C 220,36 246,218 12,120 h 244 s 34,154 56,161 C 211,204 208,60 174,14 h 155 s 157,116 220,95 C 116,164 53,210 174,232 h 139 s 148,151 135,221 C 167,196 118,27 149,247 h 233 s 129,238 113,21 C 73,44 215,158 218,29 h 68 s 13,98 243,134 C 44,98 149,35 20,178 h 163 s 219,104 41,152 C 237,107 118,120 127,117 h 57 s 41,167 43,136 C 116,168 44,246 182,209 h 143 s 238,93 237,119 C 142,36 64,67 97,111 h 71 s 230,247 119,27 C 206,56 158,51 71,115 h 135 s 120,186 74,57 C 197,165 180,214 102,16 h 88 s 252,48 189,166 C 163,237 57,253 154,60 h 96 s 84,56 15,66 C 177,101 10,202 185,227 h 29 s 204,55 115,219 C 103,82 127,143 194,99 h 102 s 179,63 84,110
|
||||
> xs.x_values = [40, 18, 3, 18]
|
||||
Arr becomes:
|
||||
xs.arr = [202, 221, 122, 9, 104, 148, 35, 141, 172, 239, 1, 134, 120, 204, 92, 116, 66, 19, 218, 104, 143, 23, 147, 213, 56, 102, 69, 212, 151, 26, 123, 178, 187, 28, 196, 43, 45, 226, 56, 69, 54, 46, 126, 103, 95, 4, 134, 84]
|
||||
*/
|
||||
|
||||
// arr = list(x_bytes) -- we already have this as the input
|
||||
let arr = x_bytes;
|
||||
|
||||
// idx = arr[x_values[0]] % 16
|
||||
let i = x_values.get(0).map(|x| *x as usize).ok_or_else(|| GrokClientError::BadSignatureInputs)?;
|
||||
let a = arr.get(i).map(|x| *x).ok_or_else(|| GrokClientError::BadSignatureInputs)?;
|
||||
let idx = a % 16;
|
||||
|
||||
println!("idx = {}", idx);
|
||||
|
||||
|
||||
|
||||
Ok("".to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::requests::index_page::signature::signature_xs::signature_xs;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
let x_bytes = [202, 221, 122, 9, 104, 148, 35, 141, 172, 239, 1, 134, 120, 204, 92, 116, 66, 19, 218, 104, 143, 23, 147, 213, 56, 102, 69, 212, 151, 26, 123, 178, 187, 28, 196, 43, 45, 226, 56, 69, 54, 46, 126, 103, 95, 4, 134, 84];
|
||||
let svg_data = "M 10,30 C 147,16 51,222 136,87 h 31 s 177,77 40,114 C 68,166 18,188 114,44 h 220 s 148,210 202,25 C 220,36 246,218 12,120 h 244 s 34,154 56,161 C 211,204 208,60 174,14 h 155 s 157,116 220,95 C 116,164 53,210 174,232 h 139 s 148,151 135,221 C 167,196 118,27 149,247 h 233 s 129,238 113,21 C 73,44 215,158 218,29 h 68 s 13,98 243,134 C 44,98 149,35 20,178 h 163 s 219,104 41,152 C 237,107 118,120 127,117 h 57 s 41,167 43,136 C 116,168 44,246 182,209 h 143 s 238,93 237,119 C 142,36 64,67 97,111 h 71 s 230,247 119,27 C 206,56 158,51 71,115 h 135 s 120,186 74,57 C 197,165 180,214 102,16 h 88 s 252,48 189,166 C 163,237 57,253 154,60 h 96 s 84,56 15,66 C 177,101 10,202 185,227 h 29 s 204,55 115,219 C 103,82 127,143 194,99 h 102 s 179,63 84,110";
|
||||
let x_values = [40, 18, 3, 18];
|
||||
|
||||
signature_xs(&x_bytes, &svg_data, &x_values).unwrap();
|
||||
|
||||
assert_eq!(1,2);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod find_script_actions_and_xsid;
|
||||
pub mod generate_sign_for_new_conversation;
|
||||
pub mod parse_numbers_from_xsid_script;
|
||||
pub mod verification_token_to_loading_anim;
|
||||
Reference in new issue
Block a user