Rust Requires Chilkat v11.0.0+
Rust
Ibanity XS2A List Financial Institutions
See more Ibanity Examples
Demonstrates how to send a request to get a list of financial institutions.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Send the following request:
// $ curl -X GET https://api.ibanity.com/xs2a/financial-institutions \
// --cert certificate.pem \
// --key private_key.pem \
// -H 'Signature: keyId="75b5d796-de5c-400a-81ce-e72371b01cbc",created=1599659223,algorithm="hs2019",headers="(request-target) digest (created) host",signature="BASE64(RSA-SHA256(SIGNING_STRING))"' \
// -H 'Digest: SHA-512=beDaRguyEb8fhh5wnl37bOTDtvhuYZyZNkTZ9LiC9Wc='
// Ibanity provides the certificate + private key in PFX format. This example will use the .pfx instead of the pair of PEM files.
// (It is also possible to implement using Chilkat with the PEM files, but PFX is easier.)
let cert = chilkat::Cert::new();
if cert.load_pfx_file("qa_data/pfx/my_ibanity_certificate.pfx", "my_pfx_password").is_err() {
println!("{}", cert.last_error_text());
return;
}
// We need to calculate the Digest and Signature header fields.
// For a detailed explanation, see Calculate Ibanity HTTP Signature Example
// We'll just write the code here as briefly as possible.
let dt_now = chilkat::DateTime::new();
let _ = dt_now.set_from_current_system_time();
let created = dt_now.get_as_unix_time_str(false).unwrap_or_default();
let crypt2 = chilkat::Crypt2::new();
crypt2.set_hash_algorithm("sha512");
crypt2.set_encoding_mode("base64");
let sb_digest_hdr_value = chilkat::StringBuilder::new();
let _ = sb_digest_hdr_value.append("SHA-512=");
// GET requests have empty payloads. The SHA-512 hash of the empty string is the same for all GET requests.
// Therefore all GET requests will use "z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg=="
// You can eliminate the explicit hash computation (for GET requests) and simply use the above literal string.
let _ = sb_digest_hdr_value.append(&crypt2.hash_string_enc("").unwrap_or_default());
println!("Generated Digest");
println!("{}", sb_digest_hdr_value.get_as_string().unwrap_or_default());
let request_target = "get /xs2a/financial-institutions".to_string();
let sb_signing_string = chilkat::StringBuilder::new();
let _ = sb_signing_string.append("(request-target): ");
let _ = sb_signing_string.append_line(&request_target, false);
let _ = sb_signing_string.append("host: ");
let _ = sb_signing_string.append_line("api.ibanity.com", false);
let _ = sb_signing_string.append("digest: ");
let _ = sb_signing_string.append_line(&sb_digest_hdr_value.get_as_string().unwrap_or_default(), false);
let _ = sb_signing_string.append("(created): ");
let _ = sb_signing_string.append(&created);
// ibanity-idempotency-key is not used with GET requests.
println!("Signing String:");
println!("{}", sb_signing_string.get_as_string().unwrap_or_default());
let signed_headers_list = "(request-target) host digest (created)".to_string();
let priv_key = chilkat::PrivateKey::new();
if priv_key.load_encrypted_pem_file("my_ibanity_signature_private_key.pem", "pem_password").is_err() {
println!("{}", priv_key.last_error_text());
return;
}
let rsa = chilkat::Rsa::new();
rsa.set_pss_salt_len(32);
rsa.set_encoding_mode("base64");
// Use the RSASSA-PSS signature algorithm
rsa.set_pkcs_padding(false);
if rsa.use_private_key(&priv_key).is_err() {
println!("{}", rsa.last_error_text());
return;
}
// Sign the signing string.
let Ok(sig_base64) = rsa.sign_string_enc(&sb_signing_string.get_as_string().unwrap_or_default(), "sha-256") else {
println!("{}", rsa.last_error_text());
return;
};
println!("Signature:");
println!("{}", sig_base64);
// Build the signature header value.
let sb_sig_header_value = chilkat::StringBuilder::new();
let _ = sb_sig_header_value.append("keyId=\"");
// Use your identifier for the application's signature certificate, obtained from the Developer Portal
let _ = sb_sig_header_value.append("a0ce296d-84c8-4bd5-8eb4-de0339950cfa");
let _ = sb_sig_header_value.append("\",created=");
let _ = sb_sig_header_value.append(&created);
let _ = sb_sig_header_value.append(",algorithm=\"hs2019\",headers=\"");
let _ = sb_sig_header_value.append(&signed_headers_list);
let _ = sb_sig_header_value.append("\",signature=\"");
let _ = sb_sig_header_value.append(&sig_base64);
let _ = sb_sig_header_value.append("\"");
// Send the GET request..
let http = chilkat::Http::new();
if http.set_ssl_client_cert(&cert).is_err() {
println!("{}", http.last_error_text());
return;
}
http.set_request_header("Signature", &sb_sig_header_value.get_as_string().unwrap_or_default());
http.set_request_header("Digest", &sb_digest_hdr_value.get_as_string().unwrap_or_default());
let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://api.ibanity.com/xs2a/financial-institutions", &sb_response_body).is_err() {
println!("{}", http.last_error_text());
return;
}
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);
println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());
let resp_status_code = http.last_status();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", http.last_header());
println!("Failed.");
return;
}
// Sample output:
// (Sample code for parsing the JSON response is shown below)
// {
// "data": [
// {
// "attributes": {
// "authorizationModels": [
// "detailed",
// "financialInstitutionOffered"
// ],
// "bic": "NBBEBEBB203",
// "bulkPaymentsEnabled": true,
// "bulkPaymentsProductTypes": [
// "sepaCreditTransfer"
// ],
// "country": null,
// "financialInstitutionCustomerReferenceRequired": false,
// "futureDatedPaymentsAllowed": true,
// "logoUrl": "https://s3.eu-central-1.amazonaws.com/ibanity-production-financial-institution-assets/sandbox.png",
// "maintenanceFrom": null,
// "maintenanceTo": null,
// "maintenanceType": null,
// "maxRequestedAccountReferences": null,
// "minRequestedAccountReferences": 0,
// "name": "Bogus Financial",
// "paymentsEnabled": true,
// "paymentsProductTypes": [
// "sepaCreditTransfer"
// ],
// "periodicPaymentsEnabled": true,
// "periodicPaymentsProductTypes": [
// "sepaCreditTransfer"
// ],
// "primaryColor": "#7d39ff",
// "requiresCredentialStorage": false,
// "requiresCustomerIpAddress": false,
// "sandbox": true,
// "secondaryColor": "#3DF2C2",
// "sharedBrandName": null,
// "sharedBrandReference": null,
// "status": "beta"
// },
// "id": "2d3d70a4-cb3c-477c-97e1-cbe495b82841",
// "links": {
// "self": "https://api.ibanity.com/xs2a/financial-institutions/2d3d70a4-cb3c-477c-97e1-cbe495b82841"
// },
// "type": "financialInstitution"
// },
// {
// "attributes": {
// "authorizationModels": [
// "detailed",
// "financialInstitutionOffered"
// ],
// "bic": "NBBEBEBB203",
// "bulkPaymentsEnabled": true,
// "bulkPaymentsProductTypes": [
// "sepaCreditTransfer"
// ],
// "country": null,
// "financialInstitutionCustomerReferenceRequired": false,
// "futureDatedPaymentsAllowed": true,
// "logoUrl": "https://s3.eu-central-1.amazonaws.com/ibanity-production-financial-institution-assets/sandbox.png",
// "maintenanceFrom": null,
// "maintenanceTo": null,
// "maintenanceType": null,
// "maxRequestedAccountReferences": null,
// "minRequestedAccountReferences": 0,
// "name": "XYZ Trust",
// "paymentsEnabled": true,
// "paymentsProductTypes": [
// "sepaCreditTransfer"
// ],
// "periodicPaymentsEnabled": true,
// "periodicPaymentsProductTypes": [
// "sepaCreditTransfer"
// ],
// "primaryColor": "#7d39ff",
// "requiresCredentialStorage": false,
// "requiresCustomerIpAddress": false,
// "sandbox": true,
// "secondaryColor": "#3DF2C2",
// "sharedBrandName": null,
// "sharedBrandReference": null,
// "status": "beta"
// },
// "id": "d4100f28-936b-4379-a3f8-86314a2014fb",
// "links": {
// "self": "https://api.ibanity.com/xs2a/financial-institutions/d4100f28-936b-4379-a3f8-86314a2014fb"
// },
// "type": "financialInstitution"
// }
// ],
// "links": {
// "first": "https://api.ibanity.com/xs2a/financial-institutions"
// },
// "meta": {
// "paging": {
// "limit": 10
// }
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
let mut j: i32 = 0;
let mut count_j: i32 = 0;
let links_first = j_resp.string_of("links.first").unwrap_or_default();
let meta_paging_limit = j_resp.int_of("meta.paging.limit");
let mut i = 0;
let count_i = j_resp.size_of_array("data");
while i < count_i {
j_resp.set_i(i);
let _ = j_resp.string_of("data[i].attributes.bic").unwrap_or_default();
let _ = j_resp.bool_of("data[i].attributes.bulkPaymentsEnabled");
let _ = j_resp.string_of("data[i].attributes.country").unwrap_or_default();
let _ = j_resp.bool_of("data[i].attributes.financialInstitutionCustomerReferenceRequired");
let _ = j_resp.bool_of("data[i].attributes.futureDatedPaymentsAllowed");
let _ = j_resp.string_of("data[i].attributes.logoUrl").unwrap_or_default();
let _ = j_resp.string_of("data[i].attributes.maintenanceFrom").unwrap_or_default();
let _ = j_resp.string_of("data[i].attributes.maintenanceTo").unwrap_or_default();
let _ = j_resp.string_of("data[i].attributes.maintenanceType").unwrap_or_default();
let _ = j_resp.string_of("data[i].attributes.maxRequestedAccountReferences").unwrap_or_default();
let _ = j_resp.int_of("data[i].attributes.minRequestedAccountReferences");
let _ = j_resp.string_of("data[i].attributes.name").unwrap_or_default();
let _ = j_resp.bool_of("data[i].attributes.paymentsEnabled");
let _ = j_resp.bool_of("data[i].attributes.periodicPaymentsEnabled");
let _ = j_resp.string_of("data[i].attributes.primaryColor").unwrap_or_default();
let _ = j_resp.bool_of("data[i].attributes.requiresCredentialStorage");
let _ = j_resp.bool_of("data[i].attributes.requiresCustomerIpAddress");
let _ = j_resp.bool_of("data[i].attributes.sandbox");
let _ = j_resp.string_of("data[i].attributes.secondaryColor").unwrap_or_default();
let _ = j_resp.string_of("data[i].attributes.sharedBrandName").unwrap_or_default();
let _ = j_resp.string_of("data[i].attributes.sharedBrandReference").unwrap_or_default();
let _ = j_resp.string_of("data[i].attributes.status").unwrap_or_default();
let _ = j_resp.string_of("data[i].id").unwrap_or_default();
let _ = j_resp.string_of("data[i].links.self").unwrap_or_default();
let _ = j_resp.string_of("data[i].type").unwrap_or_default();
j = 0;
count_j = j_resp.size_of_array("data[i].attributes.authorizationModels");
while j < count_j {
j_resp.set_j(j);
let _ = j_resp.string_of("data[i].attributes.authorizationModels[j]").unwrap_or_default();
j = j + 1;
}
j = 0;
count_j = j_resp.size_of_array("data[i].attributes.bulkPaymentsProductTypes");
while j < count_j {
j_resp.set_j(j);
let _ = j_resp.string_of("data[i].attributes.bulkPaymentsProductTypes[j]").unwrap_or_default();
j = j + 1;
}
j = 0;
count_j = j_resp.size_of_array("data[i].attributes.paymentsProductTypes");
while j < count_j {
j_resp.set_j(j);
let _ = j_resp.string_of("data[i].attributes.paymentsProductTypes[j]").unwrap_or_default();
j = j + 1;
}
j = 0;
count_j = j_resp.size_of_array("data[i].attributes.periodicPaymentsProductTypes");
while j < count_j {
j_resp.set_j(j);
let _ = j_resp.string_of("data[i].attributes.periodicPaymentsProductTypes[j]").unwrap_or_default();
j = j + 1;
}
i = i + 1;
}