File tree 3 files changed +35
-0
lines changed
3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 5
5
| [ Percent-encode a string] [ ex-percent-encode ] | [ ![ percent-encoding-badge]] [ url ] | [ ![ cat-encoding-badge]] [ cat-encoding ] |
6
6
| [ Encode a string as application/x-www-form-urlencoded] [ ex-urlencoded ] | [ ![ url-badge]] [ url ] | [ ![ cat-encoding-badge]] [ cat-encoding ] |
7
7
| [ Encode and decode hex] [ ex-hex-encode-decode ] | [ ![ data-encoding-badge]] [ data-encoding ] | [ ![ cat-encoding-badge]] [ cat-encoding ] |
8
+ | [ Encode and decode base32] [ ex-base32 ] | [ ![ data-encoding-badge]] [ data-encoding ] | [ ![ cat-encoding-badge]] [ cat-encoding ] |
8
9
| [ Encode and decode base64] [ ex-base64 ] | [ ![ base64-badge]] [ base64 ] | [ ![ cat-encoding-badge]] [ cat-encoding ] |
9
10
| [ Read CSV records] [ ex-csv-read ] | [ ![ csv-badge]] [ csv ] | [ ![ cat-encoding-badge]] [ cat-encoding ] |
10
11
| [ Read CSV records with different delimiter] [ ex-csv-delimiter ] | [ ![ csv-badge]] [ csv ] | [ ![ cat-encoding-badge]] [ cat-encoding ] |
20
21
[ ex-percent-encode ] : encoding/strings.html#percent-encode-a-string
21
22
[ ex-urlencoded ] : encoding/strings.html#encode-a-string-as-applicationx-www-form-urlencoded
22
23
[ ex-hex-encode-decode ] : encoding/strings.html#encode-and-decode-hex
24
+ [ ex-base32 ] : encoding/strings.html#encode-and-decode-base32
23
25
[ ex-base64 ] : encoding/strings.html#encode-and-decode-base64
24
26
[ ex-csv-read ] : encoding/csv.html#read-csv-records
25
27
[ ex-csv-delimiter ] : encoding/csv.html#read-csv-records-with-different-delimiter
Original file line number Diff line number Diff line change
1
+ ## Encode and decode base32
2
+
3
+ [ ![ data-encoding-badge]] [ data-encoding ] [ ![ cat-encoding-badge]] [ cat-encoding ]
4
+
5
+ The [ ` data_encoding ` ] crate provides a ` BASE32::encode ` method which takes a
6
+ ` &[u8] ` and returns a ` String ` containing the base32 representation of the data.
7
+
8
+ Similarly, a ` BASE32::decode ` method is provided which takes a ` &[u8] ` and
9
+ returns a ` Vec<u8> ` if the input data is successfully decoded.
10
+
11
+ The example below coverts ` &[u8] ` data to base32 equivalent and compares this
12
+ value to the expected value.
13
+
14
+ ``` rust,edition2018
15
+ use data_encoding::{BASE32, DecodeError};
16
+
17
+ fn main() -> Result<(), DecodeError> {
18
+ let original = b"Cooking with Rust";
19
+ let expected = "INXW623JNZTSA53JORUCAUTVON2A====";
20
+
21
+ let encoded = BASE32.encode(original);
22
+ assert_eq!(encoded, expected);
23
+
24
+ let decoded = BASE32.decode(encoded.as_bytes())?;
25
+ assert_eq!(&decoded[..], &original[..]);
26
+
27
+ Ok(())
28
+ }
29
+ ```
30
+
31
+ [ `data_encoding` ] : https://docs.rs/data-encoding/*/data_encoding/
Original file line number Diff line number Diff line change 6
6
7
7
{{#include string/hex.md}}
8
8
9
+ {{#include string/base32.md}}
10
+
9
11
{{#include string/base64.md}}
10
12
11
13
{{#include ../links.md}}
You can’t perform that action at this time.
0 commit comments