id
stringlengths
20
153
type
stringclasses
1 value
granularity
stringclasses
14 values
content
stringlengths
16
84.3k
metadata
dict
hyperswitch_fn_common_utils_-2083755975331047447
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_basic_script_tags() { assert!(contains_potential_xss_or_sqli( "<script>alert('xss')</script>" )); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_basic_script_tags", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_7143364002891547783
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_event_handlers() { assert!(contains_potential_xss_or_sqli( "onload=alert('xss') onclick=alert('xss') onmouseover=alert('xss')", )); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_event_handlers", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_8781849040704368132
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_data_url_payload() { assert!(contains_potential_xss_or_sqli( "data:text/html,<script>alert('xss')</script>", )); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_data_url_payload", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-2409012913749231653
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_iframe_javascript_src() { assert!(contains_potential_xss_or_sqli( "<iframe src=javascript:alert('xss')></iframe>", )); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_iframe_javascript_src", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_566138787880499437
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_svg_with_script() { assert!(contains_potential_xss_or_sqli( "<svg><script>alert('xss')</script></svg>", )); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_svg_with_script", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-1518953133438242220
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_object_with_js() { assert!(contains_potential_xss_or_sqli( "<object data=javascript:alert('xss')></object>", )); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_object_with_js", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_8672628317475432505
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_mixed_case_tags() { assert!(contains_potential_xss_or_sqli( "<ScRiPt>alert('xss')</ScRiPt>" )); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_mixed_case_tags", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-2073030755693876060
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_embedded_script_in_text() { assert!(contains_potential_xss_or_sqli( "Test<script>alert('xss')</script>Company", )); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_embedded_script_in_text", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-1517730119423480956
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_math_with_script() { assert!(contains_potential_xss_or_sqli( "<math><script>alert('xss')</script></math>", )); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_math_with_script", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-213426601156765380
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_basic_sql_tautology() { assert!(contains_potential_xss_or_sqli("' OR '1'='1")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_basic_sql_tautology", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-6418619637674430767
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_time_based_sqli() { assert!(contains_potential_xss_or_sqli("' OR SLEEP(5) --")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_time_based_sqli", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_1822706266218498964
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_percent_encoded_sqli() { // %27 OR %271%27=%271 is a typical encoded variant assert!(contains_potential_xss_or_sqli("%27%20OR%20%271%27%3D%271")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_percent_encoded_sqli", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-762278590974102272
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn detects_benign_html_as_suspicious() { assert!(contains_potential_xss_or_sqli("<b>Hello</b>")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "detects_benign_html_as_suspicious", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_4926611206835810758
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn allows_legitimate_plain_text() { assert!(!contains_potential_xss_or_sqli("My Test Company Ltd.")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "allows_legitimate_plain_text", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_1023698046213778683
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn allows_normal_url() { assert!(!contains_potential_xss_or_sqli("https://example.com")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "allows_normal_url", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_2421219857873276106
clm
function
// hyperswitch/crates/common_utils/src/validation.rs fn allows_percent_char_without_encoding() { assert!(!contains_potential_xss_or_sqli("Get 50% off today")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "allows_percent_char_without_encoding", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-6620239702023487891
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn fmt(val: &T, f: &mut fmt::Formatter<'_>) -> fmt::Result { let vpa_str: &str = val.as_ref(); if let Some((user_identifier, bank_or_psp)) = vpa_str.split_once('@') { let masked_user_identifier = "*".repeat(user_identifier.len()); write!(f, "{masked_user_identifier}@{bank_or_psp}") } else { WithType::fmt(val, f) } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "fmt", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_259469118307721823
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn from_str(email: &str) -> Result<Self, Self::Err> { if email.eq(REDACTED) { return Ok(Self(Secret::new(email.to_string()))); } match validate_email(email) { Ok(_) => { let secret = Secret::<String, EmailStrategy>::new(email.to_string()); Ok(Self(secret)) } Err(_) => Err(ValidationError::InvalidValue { message: "Invalid email address format".into(), } .into()), } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "from_str", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_2060619459158900507
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn try_from(value: String) -> Result<Self, Self::Error> { Self::from_str(&value).change_context(errors::ParsingError::EmailParsingError) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "try_from", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_3938000509921911262
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn deref(&self) -> &Self::Target { &self.0 }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "deref", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-5522728700003861138
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "deref_mut", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-7544579329907953937
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn build(row: Self::Row) -> deserialize::Result<Self> { Ok(row) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "build", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-3204450359509468642
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn from_sql(bytes: DB::RawValue<'_>) -> deserialize::Result<Self> { let val = String::from_sql(bytes)?; Ok(Self::from_str(val.as_str())?) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "from_sql", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-2934784631451704815
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, DB>) -> diesel::serialize::Result { self.0.to_sql(out) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "to_sql", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_3030908600696975758
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn from(item: Encryptable<Secret<String, EmailStrategy>>) -> Self { Self(item.into_inner()) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "from", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_8267195906789200325
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn expose(self) -> Secret<String, EmailStrategy> { self.0 }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "expose", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-6163667042750191912
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_valid_email_masking() { let secret: Secret<String, EmailStrategy> = Secret::new("example@test.com".to_string()); assert_eq!("*******@test.com", format!("{secret:?}")); let secret: Secret<String, EmailStrategy> = Secret::new("username@gmail.com".to_string()); assert_eq!("********@gmail.com", format!("{secret:?}")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_valid_email_masking", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_3345972809369698773
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_invalid_email_masking() { let secret: Secret<String, EmailStrategy> = Secret::new("myemailgmail.com".to_string()); assert_eq!("*** alloc::string::String ***", format!("{secret:?}")); let secret: Secret<String, EmailStrategy> = Secret::new("myemail$gmail.com".to_string()); assert_eq!("*** alloc::string::String ***", format!("{secret:?}")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_invalid_email_masking", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_6823720245295879519
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_valid_newtype_email() { let email_check = Email::from_str("example@abc.com"); assert!(email_check.is_ok()); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_valid_newtype_email", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_7324813546407034920
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_invalid_newtype_email() { let email_check = Email::from_str("example@abc@com"); assert!(email_check.is_err()); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_invalid_newtype_email", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_1806191763681535330
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_redacted_email() { let email_result = Email::from_str(REDACTED); assert!(email_result.is_ok()); if let Ok(email) = email_result { let secret_value = email.0.expose(); assert_eq!(secret_value.as_str(), REDACTED); } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_redacted_email", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-6320626401365006840
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_valid_ip_addr_masking() { let secret: Secret<String, IpAddress> = Secret::new("123.23.1.78".to_string()); assert_eq!("123.**.**.**", format!("{secret:?}")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_valid_ip_addr_masking", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-1519748195324863590
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_invalid_ip_addr_masking() { let secret: Secret<String, IpAddress> = Secret::new("123.4.56".to_string()); assert_eq!("*** alloc::string::String ***", format!("{secret:?}")); let secret: Secret<String, IpAddress> = Secret::new("123.4567.12.4".to_string()); assert_eq!("*** alloc::string::String ***", format!("{secret:?}")); let secret: Secret<String, IpAddress> = Secret::new("123..4.56".to_string()); assert_eq!("*** alloc::string::String ***", format!("{secret:?}")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_invalid_ip_addr_masking", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_609522277037552255
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_valid_client_secret_masking() { let secret: Secret<String, ClientSecret> = Secret::new("pay_uszFB2QGe9MmLY65ojhT_secret_tLjTz9tAQxUVEFqfmOIP".to_string()); assert_eq!( "pay_uszFB2QGe9MmLY65ojhT_***************************", format!("{secret:?}") ); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_valid_client_secret_masking", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_8692961773298233029
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_invalid_client_secret_masking() { let secret: Secret<String, IpAddress> = Secret::new("pay_uszFB2QGe9MmLY65ojhT_secret".to_string()); assert_eq!("*** alloc::string::String ***", format!("{secret:?}")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_invalid_client_secret_masking", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_7440595977957385886
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_valid_phone_number_default_masking() { let secret: Secret<String> = Secret::new("+40712345678".to_string()); assert_eq!("*** alloc::string::String ***", format!("{secret:?}")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_valid_phone_number_default_masking", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-2792471380531353416
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_valid_upi_vpa_masking() { let secret: Secret<String, UpiVpaMaskingStrategy> = Secret::new("my_name@upi".to_string()); assert_eq!("*******@upi", format!("{secret:?}")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_valid_upi_vpa_masking", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_7498307914731260976
clm
function
// hyperswitch/crates/common_utils/src/pii.rs fn test_invalid_upi_vpa_masking() { let secret: Secret<String, UpiVpaMaskingStrategy> = Secret::new("my_name_upi".to_string()); assert_eq!("*** alloc::string::String ***", format!("{secret:?}")); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_invalid_upi_vpa_masking", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_3209555635821851074
clm
function
// hyperswitch/crates/common_utils/src/errors.rs fn switch(&self) -> T { T::switch_from(self) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "switch", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-8528993542035379385
clm
function
// hyperswitch/crates/common_utils/src/keymanager.rs fn get_api_encryption_client( state: &KeyManagerState, ) -> errors::CustomResult<reqwest::Client, errors::KeyManagerClientError> { let get_client = || { let mut client = reqwest::Client::builder() .redirect(reqwest::redirect::Policy::none()) .pool_idle_timeout(std::time::Duration::from_secs( state.client_idle_timeout.unwrap_or_default(), )); #[cfg(feature = "keymanager_mtls")] { let cert = state.cert.clone(); let ca = state.ca.clone(); let identity = reqwest::Identity::from_pem(cert.peek().as_ref()) .change_context(errors::KeyManagerClientError::ClientConstructionFailed)?; let ca_cert = reqwest::Certificate::from_pem(ca.peek().as_ref()) .change_context(errors::KeyManagerClientError::ClientConstructionFailed)?; client = client .use_rustls_tls() .identity(identity) .add_root_certificate(ca_cert) .https_only(true); } client .build() .change_context(errors::KeyManagerClientError::ClientConstructionFailed) }; Ok(ENCRYPTION_API_CLIENT.get_or_try_init(get_client)?.clone()) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "get_api_encryption_client", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-6477904127510839215
clm
function
// hyperswitch/crates/common_utils/src/keymanager.rs pub async fn send_encryption_request<T>( state: &KeyManagerState, headers: HeaderMap, url: String, method: Method, request_body: T, ) -> errors::CustomResult<reqwest::Response, errors::KeyManagerClientError> where T: ConvertRaw, { let client = get_api_encryption_client(state)?; let url = reqwest::Url::parse(&url) .change_context(errors::KeyManagerClientError::UrlEncodingFailed)?; client .request(method, url) .json(&ConvertRaw::convert_raw(request_body)?) .headers(headers) .send() .await .change_context(errors::KeyManagerClientError::RequestNotSent( "Unable to send request to encryption service".to_string(), )) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "send_encryption_request", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-2032022329538292685
clm
function
// hyperswitch/crates/common_utils/src/keymanager.rs pub async fn call_encryption_service<T, R>( state: &KeyManagerState, method: Method, endpoint: &str, request_body: T, ) -> errors::CustomResult<R, errors::KeyManagerClientError> where T: GetKeymanagerTenant + ConvertRaw + Send + Sync + 'static + Debug, R: serde::de::DeserializeOwned, { let url = format!("{}/{endpoint}", &state.url); logger::info!(key_manager_request=?request_body); let mut header = vec![]; header.push(( HeaderName::from_str(CONTENT_TYPE) .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?, HeaderValue::from_str("application/json") .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?, )); #[cfg(feature = "km_forward_x_request_id")] if let Some(request_id) = state.request_id { header.push(( HeaderName::from_str(X_REQUEST_ID) .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?, HeaderValue::from_str(request_id.as_hyphenated().to_string().as_str()) .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?, )) } //Add Tenant ID header.push(( HeaderName::from_str(TENANT_HEADER) .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?, HeaderValue::from_str(request_body.get_tenant_id(state).get_string_repr()) .change_context(errors::KeyManagerClientError::FailedtoConstructHeader)?, )); let response = send_encryption_request( state, HeaderMap::from_iter(header.into_iter()), url, method, request_body, ) .await .map_err(|err| err.change_context(errors::KeyManagerClientError::RequestSendFailed))?; logger::info!(key_manager_response=?response); match response.status() { StatusCode::OK => response .json::<R>() .await .change_context(errors::KeyManagerClientError::ResponseDecodingFailed), StatusCode::INTERNAL_SERVER_ERROR => { Err(errors::KeyManagerClientError::InternalServerError( response .bytes() .await .change_context(errors::KeyManagerClientError::ResponseDecodingFailed)?, ) .into()) } StatusCode::BAD_REQUEST => Err(errors::KeyManagerClientError::BadRequest( response .bytes() .await .change_context(errors::KeyManagerClientError::ResponseDecodingFailed)?, ) .into()), _ => Err(errors::KeyManagerClientError::Unexpected( response .bytes() .await .change_context(errors::KeyManagerClientError::ResponseDecodingFailed)?, ) .into()), } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "call_encryption_service", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-2987587430539796733
clm
function
// hyperswitch/crates/common_utils/src/keymanager.rs fn convert_raw(self) -> Result<Self::Output, errors::KeyManagerClientError> { let data = self .data .iter() .map(|(k, v)| { let value = match String::from_utf8(v.peek().clone()) { Ok(data) => data, Err(_) => { let data = BASE64_ENGINE.encode(v.peek().clone()); format!("{DEFAULT_ENCRYPTION_VERSION}:{data}") } }; (k.to_owned(), StrongSecret::new(value)) }) .collect(); Ok(BatchDecryptDataRequest { data, identifier: self.identifier, }) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "convert_raw", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_2307980888617014653
clm
function
// hyperswitch/crates/common_utils/src/keymanager.rs pub async fn create_key_in_key_manager( state: &KeyManagerState, request_body: EncryptionCreateRequest, ) -> errors::CustomResult<DataKeyCreateResponse, errors::KeyManagerError> { call_encryption_service(state, Method::POST, "key/create", request_body) .await .change_context(errors::KeyManagerError::KeyAddFailed) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "create_key_in_key_manager", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-4755680265121562835
clm
function
// hyperswitch/crates/common_utils/src/keymanager.rs pub async fn transfer_key_to_key_manager( state: &KeyManagerState, request_body: EncryptionTransferRequest, ) -> errors::CustomResult<DataKeyCreateResponse, errors::KeyManagerError> { call_encryption_service(state, Method::POST, "key/transfer", request_body) .await .change_context(errors::KeyManagerError::KeyTransferFailed) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "transfer_key_to_key_manager", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_2200990865444446937
clm
function
// hyperswitch/crates/common_utils/src/ucs_types.rs pub fn get_string_repr(&self) -> &str { match self { Self::Payment(id) => id.get_string_repr(), Self::Refund(id) => id.get_string_repr(), } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "get_string_repr", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_2603105663375795298
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs fn is_valid_id_character(input_char: char) -> bool { input_char.is_ascii_alphanumeric() || matches!(input_char, '_' | '-') }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "is_valid_id_character", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-2779439462855487568
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs fn get_invalid_input_character(input_string: Cow<'static, str>) -> Option<char> { input_string .trim() .chars() .find(|&char| !is_valid_id_character(char)) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "get_invalid_input_character", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_5015331104098244080
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de>, { let deserialized_string = String::deserialize(deserializer)?; Self::from(deserialized_string.into()).map_err(serde::de::Error::custom) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "deserialize", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-5517540924702293491
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs pub fn from(input_string: Cow<'static, str>) -> Result<Self, LengthIdError> { let trimmed_input_string = input_string.trim().to_string(); let length_of_input_string = u8::try_from(trimmed_input_string.len()) .map_err(|_| LengthIdError::MaxLengthViolated(MAX_LENGTH))?; when(length_of_input_string > MAX_LENGTH, || { Err(LengthIdError::MaxLengthViolated(MAX_LENGTH)) })?; when(length_of_input_string < MIN_LENGTH, || { Err(LengthIdError::MinLengthViolated(MIN_LENGTH)) })?; let alphanumeric_id = match AlphaNumericId::from(trimmed_input_string.into()) { Ok(valid_alphanumeric_id) => valid_alphanumeric_id, Err(error) => Err(LengthIdError::AlphanumericIdError(error))?, }; Ok(Self(alphanumeric_id)) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "from", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-8742097276210586712
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs pub(crate) fn new_unchecked(alphanumeric_id: AlphaNumericId) -> Self { Self(alphanumeric_id) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "new_unchecked", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_126137997951333083
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs pub fn new(prefix: &str) -> Self { Self(AlphaNumericId::new(prefix)) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "new", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_1539447444311407904
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs pub(crate) fn from_alphanumeric_id( alphanumeric_id: AlphaNumericId, ) -> Result<Self, LengthIdError> { let length_of_input_string = alphanumeric_id.0.len(); let length_of_input_string = u8::try_from(length_of_input_string) .map_err(|_| LengthIdError::MaxLengthViolated(MAX_LENGTH))?; when(length_of_input_string > MAX_LENGTH, || { Err(LengthIdError::MaxLengthViolated(MAX_LENGTH)) })?; when(length_of_input_string < MIN_LENGTH, || { Err(LengthIdError::MinLengthViolated(MIN_LENGTH)) })?; Ok(Self(alphanumeric_id)) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "from_alphanumeric_id", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_2032463742412518817
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, DB>) -> diesel::serialize::Result { self.0 .0.to_sql(out) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "to_sql", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_6564966801078125684
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs fn from_sql(value: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> { let string_val = String::from_sql(value)?; Ok(Self(AlphaNumericId::new_unchecked(string_val))) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "from_sql", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_1333221017084940659
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs test_id_deserialize_underscore() { let parsed_alphanumeric_id = serde_json::from_str::<AlphaNumericId>(VALID_UNDERSCORE_ID_JSON); let alphanumeric_id = AlphaNumericId::from(EXPECTED_VALID_UNDERSCORE_ID.into()).unwrap(); assert_eq!(parsed_alphanumeric_id.unwrap(), alphanumeric_id); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "t_id_deserialize_underscore() ", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_1945903439336481934
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs test_id_deserialize_hyphen() { let parsed_alphanumeric_id = serde_json::from_str::<AlphaNumericId>(VALID_HYPHEN_ID_JSON); let alphanumeric_id = AlphaNumericId::from(VALID_HYPHEN_ID_STRING.into()).unwrap(); assert_eq!(parsed_alphanumeric_id.unwrap(), alphanumeric_id); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "t_id_deserialize_hyphen() ", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-6442101777458058715
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs test_id_deserialize_with_spaces() { let parsed_alphanumeric_id = serde_json::from_str::<AlphaNumericId>(INVALID_ID_WITH_SPACES); assert!(parsed_alphanumeric_id.is_err()); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "t_id_deserialize_with_spaces() ", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-4455834736980366832
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs test_id_deserialize_with_emojis() { let parsed_alphanumeric_id = serde_json::from_str::<AlphaNumericId>(INVALID_ID_WITH_EMOJIS); assert!(parsed_alphanumeric_id.is_err()); } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "t_id_deserialize_with_emojis() ", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_2213216456332642665
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs test_valid_reference_id() { let parsed_merchant_reference_id = serde_json::from_str::<LengthId<MAX_LENGTH, MIN_LENGTH>>(VALID_REF_ID_JSON); dbg!(&parsed_merchant_reference_id); assert!(parsed_merchant_reference_id.is_ok()); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "t_valid_reference_id() ", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_6605102926169772393
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs test_invalid_ref_id() { let parsed_merchant_reference_id = serde_json::from_str::<LengthId<MAX_LENGTH, MIN_LENGTH>>(INVALID_REF_ID_JSON); assert!(parsed_merchant_reference_id.is_err()); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "t_invalid_ref_id() ", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_4229815520560834142
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs test_invalid_ref_id_error_message() { let parsed_merchant_reference_id = serde_json::from_str::<LengthId<MAX_LENGTH, MIN_LENGTH>>(INVALID_REF_ID_JSON); let expected_error_message = r#"value `cus abcdefghijklmnopqrstuv` contains invalid character ` `"#.to_string(); let error_message = parsed_merchant_reference_id .err() .map(|error| error.to_string()); assert_eq!(error_message, Some(expected_error_message)); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "t_invalid_ref_id_error_message() ", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_8452872512260566975
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs test_invalid_ref_id_length() { let parsed_merchant_reference_id = serde_json::from_str::<LengthId<MAX_LENGTH, MIN_LENGTH>>(INVALID_REF_ID_LENGTH); dbg!(&parsed_merchant_reference_id); let expected_error_message = format!("the maximum allowed length for this field is {MAX_LENGTH}"); assert!(parsed_merchant_reference_id .is_err_and(|error_string| error_string.to_string().eq(&expected_error_message))); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "t_invalid_ref_id_length() ", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_3737109934581180171
clm
function
// hyperswitch/crates/common_utils/src/id_type.rs test_invalid_ref_id_length_error_type() { let parsed_merchant_reference_id = LengthId::<MAX_LENGTH, MIN_LENGTH>::from(INVALID_REF_ID_LENGTH.into()); dbg!(&parsed_merchant_reference_id); assert!( parsed_merchant_reference_id.is_err_and(|error_type| matches!( error_type, LengthIdError::MaxLengthViolated(MAX_LENGTH) )) ); } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "t_invalid_ref_id_length_error_type() ", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_2550660168371387971
clm
function
// hyperswitch/crates/common_utils/src/macros.rs fn test_enum_from_str_ok() { // Success cases just parse directly let parsed_a: TestEnum = "VariantA:42".parse().unwrap(); // Unwrapping Infallible is fine assert_eq!(parsed_a, TestEnum::VariantA { value: 42 }); let parsed_b: TestEnum = "VariantB:hello world".parse().unwrap(); assert_eq!( parsed_b, TestEnum::VariantB { text: "hello world".to_string() } ); let parsed_c: TestEnum = "VariantC:123456789012345".parse().unwrap(); assert_eq!( parsed_c, TestEnum::VariantC { id: 123456789012345 } ); let parsed_json: TestEnum = r#"VariantJson:{"ok":true}"#.parse().unwrap(); assert_eq!( parsed_json, TestEnum::VariantJson { data: json!({"ok": true}) } ); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_enum_from_str_ok", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-6517112435807393112
clm
function
// hyperswitch/crates/common_utils/src/macros.rs fn test_enum_from_str_failures_yield_invalid() { // Missing delimiter let parsed: TestEnum = "VariantA".parse().unwrap(); assert_eq!(parsed, TestEnum::Invalid); // Unknown tag let parsed: TestEnum = "UnknownVariant:123".parse().unwrap(); assert_eq!(parsed, TestEnum::Invalid); // Bad field data for i32 let parsed: TestEnum = "VariantA:not_a_number".parse().unwrap(); assert_eq!(parsed, TestEnum::Invalid); // Bad field data for JsonValue let parsed: TestEnum = r#"VariantJson:{"bad_json"#.parse().unwrap(); assert_eq!(parsed, TestEnum::Invalid); // Empty field data for non-string (e.g., i32) let parsed: TestEnum = "VariantA:".parse().unwrap(); assert_eq!(parsed, TestEnum::Invalid); // Empty field data for string IS valid for String type let parsed_str: TestEnum = "VariantB:".parse().unwrap(); assert_eq!( parsed_str, TestEnum::VariantB { text: "".to_string() } ); // Parsing the literal "Invalid" string let parsed_invalid_str: TestEnum = "Invalid".parse().unwrap(); assert_eq!(parsed_invalid_str, TestEnum::Invalid); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_enum_from_str_failures_yield_invalid", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-7576328177772414010
clm
function
// hyperswitch/crates/common_utils/src/macros.rs fn test_enum_display_and_serialize() { // Display valid let value_a = TestEnum::VariantA { value: 99 }; assert_eq!(value_a.to_string(), "VariantA:99"); // Serialize valid let json_a = serde_json::to_string(&value_a).expect("Serialize A failed"); assert_eq!(json_a, "\"VariantA:99\""); // Serializes to JSON string // Display Invalid let value_invalid = TestEnum::Invalid; assert_eq!(value_invalid.to_string(), "Invalid"); // Serialize Invalid let json_invalid = serde_json::to_string(&value_invalid).expect("Serialize Invalid failed"); assert_eq!(json_invalid, "\"Invalid\""); // Serializes to JSON string "Invalid" }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_enum_display_and_serialize", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-4816377483878685943
clm
function
// hyperswitch/crates/common_utils/src/macros.rs fn test_enum_deserialize() { // Deserialize valid let input_a = "\"VariantA:123\""; let deserialized_a: TestEnum = serde_json::from_str(input_a).expect("Deserialize A failed"); assert_eq!(deserialized_a, TestEnum::VariantA { value: 123 }); // Deserialize explicit "Invalid" let input_invalid = "\"Invalid\""; let deserialized_invalid: TestEnum = serde_json::from_str(input_invalid).expect("Deserialize Invalid failed"); assert_eq!(deserialized_invalid, TestEnum::Invalid); // Deserialize malformed string (according to macro rules) -> Invalid let input_malformed = "\"VariantA_no_delimiter\""; let deserialized_malformed: TestEnum = serde_json::from_str(input_malformed).expect("Deserialize malformed should succeed"); assert_eq!(deserialized_malformed, TestEnum::Invalid); // Deserialize string with bad field data -> Invalid let input_bad_data = "\"VariantA:not_a_number\""; let deserialized_bad_data: TestEnum = serde_json::from_str(input_bad_data).expect("Deserialize bad data should succeed"); assert_eq!(deserialized_bad_data, TestEnum::Invalid); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_enum_deserialize", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-6455310206383930450
clm
function
// hyperswitch/crates/common_utils/src/link_utils.rs fn default() -> Self { Self::PaymentMethodCollect(PaymentMethodCollectStatus::Initiated) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "default", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-8671321260867849549
clm
function
// hyperswitch/crates/common_utils/src/link_utils.rs fn from_sql(bytes: DB::RawValue<'_>) -> deserialize::Result<Self> { let value = <serde_json::Value as FromSql<Jsonb, DB>>::from_sql(bytes)?; let generic_status: GenericLinkStatus = serde_json::from_value(value)?; match generic_status { GenericLinkStatus::PayoutLink(status) => Ok(status), GenericLinkStatus::PaymentMethodCollect(_) => { Err(report!(ParsingError::EnumParseFailure("PayoutLinkStatus"))) .attach_printable("Invalid status for PayoutLink")? } } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "from_sql", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_7846376343102825574
clm
function
// hyperswitch/crates/common_utils/src/link_utils.rs fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, diesel::pg::Pg>) -> diesel::serialize::Result { let value = serde_json::to_value(GenericLinkStatus::PayoutLink(self.clone()))?; // the function `reborrow` only works in case of `Pg` backend. But, in case of other backends // please refer to the diesel migration blog: // https://github.com/Diesel-rs/Diesel/blob/master/guide_drafts/migration_guide.md#changed-tosql-implementations <serde_json::Value as ToSql<Jsonb, diesel::pg::Pg>>::to_sql(&value, &mut out.reborrow()) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "to_sql", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_2669315079887913930
clm
function
// hyperswitch/crates/common_utils/src/link_utils.rs pub fn validate_strict_domain(domain: &str) -> bool { Regex::new(consts::STRICT_DOMAIN_REGEX) .map(|regex| regex.is_match(domain)) .map_err(|err| { let err_msg = format!("Invalid strict domain regex: {err:?}"); #[cfg(feature = "logs")] logger::error!(err_msg); err_msg }) .unwrap_or(false) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "validate_strict_domain", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_8034221745649995697
clm
function
// hyperswitch/crates/common_utils/src/link_utils.rs pub fn validate_wildcard_domain(domain: &str) -> bool { Regex::new(consts::WILDCARD_DOMAIN_REGEX) .map(|regex| regex.is_match(domain)) .map_err(|err| { let err_msg = format!("Invalid strict domain regex: {err:?}"); #[cfg(feature = "logs")] logger::error!(err_msg); err_msg }) .unwrap_or(false) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "validate_wildcard_domain", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-1131137547912308926
clm
function
// hyperswitch/crates/common_utils/src/link_utils.rs fn test_validate_strict_domain_regex() { assert!( Regex::new(consts::STRICT_DOMAIN_REGEX).is_ok(), "Strict domain regex is invalid" ); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_validate_strict_domain_regex", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-1585546724400226795
clm
function
// hyperswitch/crates/common_utils/src/link_utils.rs fn test_validate_wildcard_domain_regex() { assert!( Regex::new(consts::WILDCARD_DOMAIN_REGEX).is_ok(), "Wildcard domain regex is invalid" ); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_validate_wildcard_domain_regex", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-3769580195539999398
clm
function
// hyperswitch/crates/common_utils/src/link_utils.rs fn test_validate_strict_domain() { let valid_domains = vec![ "example.com", "example.subdomain.com", "https://example.com:8080", "http://example.com", "example.com:8080", "example.com:443", "localhost:443", "127.0.0.1:443", ]; for domain in valid_domains { assert!( validate_strict_domain(domain), "Could not validate strict domain: {domain}", ); } let invalid_domains = vec![ "", "invalid.domain.", "not_a_domain", "http://example.com/path?query=1#fragment", "127.0.0.1.2:443", ]; for domain in invalid_domains { assert!( !validate_strict_domain(domain), "Could not validate invalid strict domain: {domain}", ); } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_validate_strict_domain", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-2977313211895659937
clm
function
// hyperswitch/crates/common_utils/src/link_utils.rs fn test_validate_wildcard_domain() { let valid_domains = vec![ "example.com", "example.subdomain.com", "https://example.com:8080", "http://example.com", "example.com:8080", "example.com:443", "localhost:443", "127.0.0.1:443", "*.com", "example.*.com", "example.com:*", "*:443", "localhost:*", "127.0.0.*:*", "*:*", ]; for domain in valid_domains { assert!( validate_wildcard_domain(domain), "Could not validate wildcard domain: {domain}", ); } let invalid_domains = vec![ "", "invalid.domain.", "not_a_domain", "http://example.com/path?query=1#fragment", "*.", ".*", "example.com:*:", "*:443:", ":localhost:*", "127.00.*:*", ]; for domain in invalid_domains { assert!( !validate_wildcard_domain(domain), "Could not validate invalid wildcard domain: {domain}", ); } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_validate_wildcard_domain", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-4900024253651647343
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs pub fn new( masked_data: Secret<T, S>, encrypted_data: Secret<Vec<u8>, EncryptionStrategy>, ) -> Self { Self { inner: masked_data, encrypted: encrypted_data, } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "new", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-657135510012079658
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn current(&self) -> [u8; aead::NONCE_LEN] { let mut nonce = [0_u8; aead::NONCE_LEN]; nonce.copy_from_slice(&self.0.to_be_bytes()[Self::SEQUENCE_NUMBER_START_INDEX..]); nonce }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "current", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-1354932893859115811
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn from_bytes(bytes: [u8; aead::NONCE_LEN]) -> Self { let mut sequence_number = [0_u8; 128 / 8]; sequence_number[Self::SEQUENCE_NUMBER_START_INDEX..].copy_from_slice(&bytes); let sequence_number = u128::from_be_bytes(sequence_number); Self(sequence_number) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "from_bytes", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_495842544111623852
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn advance(&mut self) -> Result<aead::Nonce, ring::error::Unspecified> { let mut nonce = [0_u8; aead::NONCE_LEN]; nonce.copy_from_slice(&self.0.to_be_bytes()[Self::SEQUENCE_NUMBER_START_INDEX..]); // Increment sequence number self.0 = self.0.wrapping_add(1); // Return previous sequence number as bytes Ok(aead::Nonce::assume_unique_for_key(nonce)) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "advance", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_907090481269757022
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn sign_message( &self, private_key_pem_bytes: &[u8], msg_to_sign: &[u8], ) -> CustomResult<Vec<u8>, errors::CryptoError> { let parsed_pem = pem::parse(private_key_pem_bytes) .change_context(errors::CryptoError::EncodingFailed) .attach_printable("Failed to parse PEM string")?; let key_pair = match parsed_pem.tag() { "PRIVATE KEY" => RsaKeyPair::from_pkcs8(parsed_pem.contents()) .change_context(errors::CryptoError::InvalidKeyLength) .attach_printable("Failed to parse PKCS#8 DER with ring"), "RSA PRIVATE KEY" => RsaKeyPair::from_der(parsed_pem.contents()) .change_context(errors::CryptoError::InvalidKeyLength) .attach_printable("Failed to parse PKCS#1 DER (using from_der) with ring"), tag => Err(errors::CryptoError::InvalidKeyLength).attach_printable(format!( "Unexpected PEM tag: {tag}. Expected 'PRIVATE KEY' or 'RSA PRIVATE KEY'", )), }?; let rng = ring_rand::SystemRandom::new(); let signature_len = key_pair.public().modulus_len(); let mut signature_bytes = vec![0; signature_len]; key_pair .sign(&RSA_PSS_SHA256, &rng, msg_to_sign, &mut signature_bytes) .change_context(errors::CryptoError::EncodingFailed) .attach_printable("Failed to sign data with ring")?; Ok(signature_bytes) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "sign_message", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-7720727859901275555
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn verify_signature( &self, secret: &[u8], signature: &[u8], msg: &[u8], ) -> CustomResult<bool, errors::CryptoError> { // create verifying key let decoded_public_key = BASE64_ENGINE .decode(secret) .change_context(errors::CryptoError::SignatureVerificationFailed) .attach_printable("base64 decoding failed")?; let string_public_key = String::from_utf8(decoded_public_key) .change_context(errors::CryptoError::SignatureVerificationFailed) .attach_printable("utf8 to string parsing failed")?; let rsa_public_key = rsa::RsaPublicKey::from_public_key_pem(&string_public_key) .change_context(errors::CryptoError::SignatureVerificationFailed) .attach_printable("rsa public key transformation failed")?; let verifying_key = rsa::pkcs1v15::VerifyingKey::<rsa::sha2::Sha256>::new(rsa_public_key); // transfrom the signature let decoded_signature = BASE64_ENGINE .decode(signature) .change_context(errors::CryptoError::SignatureVerificationFailed) .attach_printable("base64 decoding failed")?; let rsa_signature = rsa::pkcs1v15::Signature::try_from(&decoded_signature[..]) .change_context(errors::CryptoError::SignatureVerificationFailed) .attach_printable("rsa signature transformation failed")?; // signature verification verifying_key .verify(msg, &rsa_signature) .map(|_| true) .change_context(errors::CryptoError::SignatureVerificationFailed) .attach_printable("signature verification step failed") }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "verify_signature", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_3008560203289310960
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn encode_message( &self, secret: &[u8], msg: &[u8], ) -> CustomResult<Vec<u8>, errors::CryptoError> { if secret.len() != Self::TRIPLE_DES_KEY_LENGTH { Err(errors::CryptoError::InvalidKeyLength)? } let mut buffer = msg.to_vec(); if let common_enums::CryptoPadding::ZeroPadding = self.padding { let pad_len = Self::TRIPLE_DES_IV_LENGTH - (buffer.len() % Self::TRIPLE_DES_IV_LENGTH); if pad_len != Self::TRIPLE_DES_IV_LENGTH { buffer.extend(vec![0u8; pad_len]); } }; let cipher = openssl::symm::Cipher::des_ede3_cbc(); openssl::symm::encrypt(cipher, secret, Some(&self.iv), &buffer) .change_context(errors::CryptoError::EncodingFailed) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "encode_message", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-1873888363898312030
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn decode_message( &self, secret: &[u8], msg: Secret<Vec<u8>, EncryptionStrategy>, ) -> CustomResult<Vec<u8>, errors::CryptoError> { let msg = msg.expose(); let key = UnboundKey::new(&aead::AES_256_GCM, secret) .change_context(errors::CryptoError::DecodingFailed)?; let nonce_sequence = NonceSequence::from_bytes( <[u8; aead::NONCE_LEN]>::try_from( msg.get(..aead::NONCE_LEN) .ok_or(errors::CryptoError::DecodingFailed) .attach_printable("Failed to read the nonce form the encrypted ciphertext")?, ) .change_context(errors::CryptoError::DecodingFailed)?, ); let mut key = OpeningKey::new(key, nonce_sequence); let mut binding = msg; let output = binding.as_mut_slice(); let result = key .open_within(aead::Aad::empty(), output, aead::NONCE_LEN..) .change_context(errors::CryptoError::DecodingFailed)?; Ok(result.to_vec()) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "decode_message", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_2313128696920694180
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn validate_inputs( public_key: &[u8], signature: &[u8], ) -> CustomResult<(), errors::CryptoError> { // Validate public key length if public_key.len() != Self::ED25519_PUBLIC_KEY_LEN { return Err(errors::CryptoError::InvalidKeyLength).attach_printable(format!( "Invalid ED25519 public key length: expected {} bytes, got {}", Self::ED25519_PUBLIC_KEY_LEN, public_key.len() )); } // Validate signature length if signature.len() != Self::ED25519_SIGNATURE_LEN { return Err(errors::CryptoError::InvalidKeyLength).attach_printable(format!( "Invalid ED25519 signature length: expected {} bytes, got {}", Self::ED25519_SIGNATURE_LEN, signature.len() )); } Ok(()) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "validate_inputs", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-6323189500483167508
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn generate_digest(&self, message: &[u8]) -> CustomResult<Vec<u8>, errors::CryptoError> { let digest = ring::digest::digest(&ring::digest::SHA256, message); Ok(digest.as_ref().to_vec()) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "generate_digest", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_8621157540316245369
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs pub fn generate_cryptographically_secure_random_string(length: usize) -> String { use rand::distributions::DistString; rand::distributions::Alphanumeric.sample_string(&mut rand::rngs::OsRng, length) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "generate_cryptographically_secure_random_string", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-7334650091428996355
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs pub fn generate_cryptographically_secure_random_bytes<const N: usize>() -> [u8; N] { use rand::RngCore; let mut bytes = [0; N]; rand::rngs::OsRng.fill_bytes(&mut bytes); bytes }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "generate_cryptographically_secure_random_bytes", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_8773007481779286927
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs pub fn into_inner(self) -> T { self.inner }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "into_inner", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-1239523274724410296
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs pub fn get_inner(&self) -> &T { &self.inner }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "get_inner", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_6697874366241496243
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs pub fn into_encrypted(self) -> Secret<Vec<u8>, EncryptionStrategy> { self.encrypted }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "into_encrypted", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_8419415843299016849
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs pub fn deserialize_inner_value<U, F>( self, f: F, ) -> CustomResult<Encryptable<U>, errors::ParsingError> where F: FnOnce(T) -> CustomResult<U, errors::ParsingError>, U: Clone, { let inner = self.inner; let encrypted = self.encrypted; let inner = f(inner)?; Ok(Encryptable { inner, encrypted }) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "deserialize_inner_value", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_2210181290276166899
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs pub fn map<U: Clone>(self, f: impl FnOnce(T) -> U) -> Encryptable<U> { let encrypted_data = self.encrypted; let masked_data = f(self.inner); Encryptable { inner: masked_data, encrypted: encrypted_data, } }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "map", "is_async": false, "is_pub": true, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_6505813297899545370
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn deref(&self) -> &Self::Target { &self.inner }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "deref", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-4913263947408517501
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer, { self.inner.serialize(serializer) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "serialize", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_8743242434809503309
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn eq(&self, other: &Self) -> bool { self.inner.eq(&other.inner) }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "eq", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_8284232220149045959
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn test_hmac_sha256_sign_message() { let message = r#"{"type":"payment_intent"}"#.as_bytes(); let secret = "hmac_secret_1234".as_bytes(); let right_signature = hex::decode("d5550730377011948f12cc28889bee590d2a5434d6f54b87562f2dbc2657823e") .expect("Right signature decoding"); let signature = super::HmacSha256 .sign_message(secret, message) .expect("Signature"); assert_eq!(signature, right_signature); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_hmac_sha256_sign_message", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_-1465407364524258123
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn test_hmac_sha256_verify_signature() { let right_signature = hex::decode("d5550730377011948f12cc28889bee590d2a5434d6f54b87562f2dbc2657823e") .expect("Right signature decoding"); let wrong_signature = hex::decode("d5550730377011948f12cc28889bee590d2a5434d6f54b87562f2dbc2657823f") .expect("Wrong signature decoding"); let secret = "hmac_secret_1234".as_bytes(); let data = r#"{"type":"payment_intent"}"#.as_bytes(); let right_verified = super::HmacSha256 .verify_signature(secret, &right_signature, data) .expect("Right signature verification result"); assert!(right_verified); let wrong_verified = super::HmacSha256 .verify_signature(secret, &wrong_signature, data) .expect("Wrong signature verification result"); assert!(!wrong_verified); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_hmac_sha256_verify_signature", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }
hyperswitch_fn_common_utils_5288544423232829629
clm
function
// hyperswitch/crates/common_utils/src/crypto.rs fn test_sha256_verify_signature() { let right_signature = hex::decode("123250a72f4e961f31661dbcee0fec0f4714715dc5ae1b573f908a0a5381ddba") .expect("Right signature decoding"); let wrong_signature = hex::decode("123250a72f4e961f31661dbcee0fec0f4714715dc5ae1b573f908a0a5381ddbb") .expect("Wrong signature decoding"); let secret = "".as_bytes(); let data = r#"AJHFH9349JASFJHADJ9834115USD2020-11-13.13:22:34711000000021406655APPROVED12345product_id"#.as_bytes(); let right_verified = super::Sha256 .verify_signature(secret, &right_signature, data) .expect("Right signature verification result"); assert!(right_verified); let wrong_verified = super::Sha256 .verify_signature(secret, &wrong_signature, data) .expect("Wrong signature verification result"); assert!(!wrong_verified); }
{ "chunk": null, "crate": "common_utils", "enum_name": null, "file_size": null, "for_type": null, "function_name": "test_sha256_verify_signature", "is_async": false, "is_pub": false, "lines": null, "method_name": null, "num_enums": null, "num_items": null, "num_structs": null, "repo": "hyperswitch", "start_line": null, "struct_name": null, "total_crates": null, "trait_name": null }