Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Commit

Permalink
Update Rust crate base64 to 0.21.0 (#1709)
Browse files Browse the repository at this point in the history
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [base64](https://github.com/marshallpierce/rust-base64) | dependencies | minor | `0.20.0` -> `0.21.0` |

---

### Release Notes

<details>
<summary>marshallpierce/rust-base64</summary>

### [`v0.21.0`](https://github.com/marshallpierce/rust-base64/blob/HEAD/RELEASE-NOTES.md#&#8203;0210)

[Compare Source](marshallpierce/rust-base64@v0.20.0...v0.21.0)

(not yet released)

#### Migration

##### Functions

| < 0.20 function         | 0.21 equivalent                                                                     |
|-------------------------|-------------------------------------------------------------------------------------|
| `encode()`              | `engine::general_purpose::STANDARD.encode()` or `prelude::BASE64_STANDARD.encode()` |
| `encode_config()`       | `engine.encode()`                                                                   |
| `encode_config_buf()`   | `engine.encode_string()`                                                            |
| `encode_config_slice()` | `engine.encode_slice()`                                                             |
| `decode()`              | `engine::general_purpose::STANDARD.decode()` or `prelude::BASE64_STANDARD.decode()` |
| `decode_config()`       | `engine.decode()`                                                                   |
| `decode_config_buf()`   | `engine.decode_vec()`                                                               |
| `decode_config_slice()` | `engine.decode_slice()`                                                             |

The short-lived 0.20 functions were the 0.13 functions with `config` replaced with `engine`.

##### Padding

If applicable, use the preset engines `engine::STANDARD`, `engine::STANDARD_NO_PAD`, `engine::URL_SAFE`,
or `engine::URL_SAFE_NO_PAD`.
The `NO_PAD` ones require that padding is absent when decoding, and the others require that
canonical padding is present .

If you need the < 0.20 behavior that did not care about padding, or want to recreate < 0.20.0's predefined `Config`s
precisely, see the following table.

| 0.13.1 Config   | 0.20.0+ alphabet | `encode_padding` | `decode_padding_mode` |
|-----------------|------------------|------------------|-----------------------|
| STANDARD        | STANDARD         | true             | Indifferent           |
| STANDARD_NO_PAD | STANDARD         | false            | Indifferent           |
| URL_SAFE        | URL_SAFE         | true             | Indifferent           |
| URL_SAFE_NO_PAD | URL_SAFE         | false            | Indifferent           |

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC45My4wIiwidXBkYXRlZEluVmVyIjoiMzQuOTMuMCJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Co-authored-by: crapStone <crapstone01@gmail.com>
Co-authored-by: crapStone <crapstone@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1709
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
  • Loading branch information
4 people committed Jan 9, 2023
1 parent 58018b8 commit 588355e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 66 deletions.
2 changes: 1 addition & 1 deletion crates/config/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
base64 = "0.20.0"
base64 = "0.21.0"
directories-next = "2.0.0"
lazy_static = "1.4.0"
log = "0.4.17"
Expand Down
13 changes: 11 additions & 2 deletions crates/config/src/handler.rs
@@ -1,5 +1,6 @@
use std::{collections::HashMap, env, path::PathBuf};

use base64::{prelude::BASE64_STANDARD, Engine};
use directories_next::ProjectDirs;
use lazy_static::lazy_static;
use serde_json::Value;
Expand All @@ -15,6 +16,8 @@ use super::{
types::{BackendConfig, FrontendConfig, GHSSymbols, LocalizedStrings, LocalizedStringsHeader},
};

const BASE64_IMAGE_TAG: &str = "data:image/image/png;base64,";

lazy_static! {
pub static ref PROJECT_DIRS: ProjectDirs = ProjectDirs::from("de", "Calciumdibromid", "CaBr2").unwrap();
pub static ref DATA_DIR: PathBuf = get_program_data_dir();
Expand Down Expand Up @@ -81,25 +84,31 @@ pub async fn get_hazard_symbols() -> Result<GHSSymbols> {

let mut symbols = HashMap::new();
let mut buf = Vec::new();
let mut str_buf = BASE64_IMAGE_TAG.to_string();

for filename in symbol_folder
.read_dir()?
.filter(|p| p.is_ok())
.map(|p| p.unwrap().path())
.filter(|p| p.is_file())
{
buf.clear();
let mut file = OpenOptions::new().read(true).open(&filename).await?;
buf.clear();
file.read_to_end(&mut buf).await?;

// trim only base64 data -> reuse buffer
str_buf.truncate(BASE64_IMAGE_TAG.len());
BASE64_STANDARD.encode_string(&buf, &mut str_buf);

symbols.insert(
filename
.file_name()
.unwrap()
.to_string_lossy()
.trim_end_matches(".png")
.into(),
format!("data:image/image/png;base64,{}", base64::encode(&buf)),
// clone only allocates .len() bytes
str_buf.clone(),
);
}

Expand Down
64 changes: 32 additions & 32 deletions frontend/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions frontend/src-wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 588355e

Please sign in to comment.