Formatting
Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
parent
6255dc1c2f
commit
3de7ca94a2
@ -1,12 +1,12 @@
|
||||
use anyhow::anyhow;
|
||||
use isahc::{ReadResponseExt, RequestExt};
|
||||
use isahc::http::StatusCode;
|
||||
use isahc::{ReadResponseExt, RequestExt};
|
||||
use rsa::pkcs1::{DecodeRsaPrivateKey, EncodeRsaPrivateKey, LineEnding};
|
||||
use rsa::pkcs8::EncodePublicKey;
|
||||
use rsa::RsaPrivateKey;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{BASE_URL, BunqClient, deserialize_retarded_response, sign};
|
||||
use crate::{deserialize_retarded_response, sign, BunqClient, BASE_URL};
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
struct AppState {
|
||||
@ -22,11 +22,17 @@ pub struct BunqConfig {
|
||||
|
||||
impl BunqConfig {
|
||||
pub fn load() -> anyhow::Result<BunqConfig> {
|
||||
println!("Loading config file from {}", confy::get_configuration_file_path("bunq-rs", "bunq-rs")?.to_string_lossy());
|
||||
println!(
|
||||
"Loading config file from {}",
|
||||
confy::get_configuration_file_path("bunq-rs", "bunq-rs")?.to_string_lossy()
|
||||
);
|
||||
Ok(confy::load("bunq-rs", "bunq-rs")?)
|
||||
}
|
||||
pub fn save(&self) -> anyhow::Result<()> {
|
||||
println!("Storing config file in {}", confy::get_configuration_file_path("bunq-rs", None)?.to_string_lossy());
|
||||
println!(
|
||||
"Storing config file in {}",
|
||||
confy::get_configuration_file_path("bunq-rs", None)?.to_string_lossy()
|
||||
);
|
||||
confy::store("bunq-rs", "bunq-rs", self)?;
|
||||
Ok(())
|
||||
}
|
||||
@ -41,7 +47,9 @@ impl BunqConfig {
|
||||
let bits = 2048;
|
||||
let keypair = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key");
|
||||
|
||||
let pem_public = keypair.to_public_key().to_public_key_pem(LineEnding::CRLF)?;
|
||||
let pem_public = keypair
|
||||
.to_public_key()
|
||||
.to_public_key_pem(LineEnding::CRLF)?;
|
||||
|
||||
let body = Installation {
|
||||
client_public_key: &pem_public,
|
||||
@ -72,7 +80,10 @@ impl BunqConfig {
|
||||
return Err(anyhow!(response_text));
|
||||
}
|
||||
|
||||
self.state = Some(AppState { pem_private: keypair.to_pkcs1_pem(LineEnding::CRLF)?.to_string(), token });
|
||||
self.state = Some(AppState {
|
||||
pem_private: keypair.to_pkcs1_pem(LineEnding::CRLF)?.to_string(),
|
||||
token,
|
||||
});
|
||||
self.save()?;
|
||||
|
||||
keypair
|
||||
|
@ -1,8 +1,8 @@
|
||||
use anyhow::Result;
|
||||
use rsa::pkcs1v15::SigningKey;
|
||||
use rsa::RsaPrivateKey;
|
||||
use rsa::sha2::Sha256;
|
||||
use rsa::signature::RandomizedSigner;
|
||||
use rsa::RsaPrivateKey;
|
||||
use serde::{de::DeserializeOwned, Deserialize};
|
||||
|
||||
pub use config::BunqConfig;
|
||||
@ -94,7 +94,7 @@ fn deserialize_normal_response<T: DeserializeOwned>(r: &str) -> Result<Response<
|
||||
}
|
||||
|
||||
fn sign(body: &str, key: &RsaPrivateKey) -> Result<String> {
|
||||
use base64::prelude::{BASE64_STANDARD, Engine};
|
||||
use base64::prelude::{Engine, BASE64_STANDARD};
|
||||
|
||||
let signing_key = SigningKey::<Sha256>::new(key.clone());
|
||||
let mut rng = rand::thread_rng();
|
||||
|
@ -1,7 +1,7 @@
|
||||
use isahc::{ReadResponseExt, RequestExt};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{BASE_URL, BunqClient};
|
||||
use crate::{BunqClient, BASE_URL};
|
||||
|
||||
pub(super) fn get(client: &BunqClient) -> anyhow::Result<Vec<MonetaryAccount>> {
|
||||
let response = isahc::http::Request::get(format!(
|
||||
|
@ -2,13 +2,14 @@ use anyhow::Result;
|
||||
use isahc::{ReadResponseExt, RequestExt};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{BASE_URL, BunqClient, MonetaryAccount, Pagination, Response};
|
||||
use crate::{BunqClient, MonetaryAccount, Pagination, Response, BASE_URL};
|
||||
|
||||
pub(super) fn get_from_to(client: &BunqClient,
|
||||
pub(super) fn get_from_to(
|
||||
client: &BunqClient,
|
||||
acc: &MonetaryAccount,
|
||||
from: Option<i64>,
|
||||
to: Option<i64>) -> Result<Vec<Payment>>
|
||||
{
|
||||
to: Option<i64>,
|
||||
) -> Result<Vec<Payment>> {
|
||||
let next_page = |url: &str| -> Result<(_, _)> {
|
||||
let response = isahc::http::Request::get(url)
|
||||
.header("X-Bunq-Client-Authentication", &client.token)
|
||||
|
Loading…
Reference in New Issue
Block a user