Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/base64ct/src/lib.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / base64ct / src / lib.rs` 108 lines ยท 2817 bytes Raw Blame History 1 #![no_std] 2 #![cfg_attr(docsrs, feature(doc_cfg))] 3 #![doc( 4 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/`6ee8e381`/logo.svg", 5 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/`6ee8e381`/logo.svg" 6 )] 7 #![doc = include_str!("../README.md")] 8 #![warn( 9 clippy::arithmetic_side_effects, 10 clippy::mod_module_files, 11 clippy::panic, 12 clippy::panic_in_result_fn, 13 clippy::unwrap_used, 14 missing_docs, 15 rust_2018_idioms, 16 unsafe_code, 17 unused_lifetimes, 18 unused_qualifications 19 )] 20 21 //! # Usage 22 //! 23 //! ## Allocating (enable `alloc` crate feature) 24 //! 25 //! ``` 26 //! # #[cfg(feature = "alloc")] 27 //! # { 28 //! use base64ct::{Base64, Encoding}; 29 //! 30 //! let bytes = b"example bytestring!"; 31 //! let encoded = Base64::encode_string(bytes); 32 //! assert_eq!(encoded, "ZXhhbXBsZSBieXRlc3RyaW5nIQ=="); 33 //! 34 //! let decoded = Base64::decode_vec(&encoded).unwrap(); 35 //! assert_eq!(decoded, bytes); 36 //! # } 37 //! ``` 38 //! 39 //! ## Heapless `no_std` usage 40 //! 41 //! ``` 42 //! use base64ct::{Base64, Encoding}; 43 //! 44 //! const BUF_SIZE: usize = 128; 45 //! 46 //! let bytes = b"example bytestring!"; 47 //! assert!(Base64::encoded_len(bytes) <= BUF_SIZE); 48 //! 49 //! let mut enc_buf = [0u8; BUF_SIZE]; 50 //! let encoded = Base64::encode(bytes, &mut enc_buf).unwrap(); 51 //! assert_eq!(encoded, "ZXhhbXBsZSBieXRlc3RyaW5nIQ=="); 52 //! 53 //! let mut dec_buf = [0u8; BUF_SIZE]; 54 //! let decoded = Base64::decode(encoded, &mut dec_buf).unwrap(); 55 //! assert_eq!(decoded, bytes); 56 //! ``` 57 //! 58 //! # Implementation 59 //! 60 //! Implemented using integer arithmetic alone without any lookup tables or 61 //! data-dependent branches, thereby providing portable "best effort" 62 //! constant-time operation. 63 //! 64 //! Not constant-time with respect to message length (only data). 65 //! 66 //! Adapted from the following constant-time C++ implementation of Base64: 67 //! 68 //! 69 //! 70 //! Copyright (c) 2014 Steve "Sc00bz" Thomas (steve at tobtu dot com). 71 //! Derived code is dual licensed MIT + Apache 2 (with permission from Sc00bz). 72 73 #[cfg(feature = "alloc")] 74 #[macro_use] 75 extern crate alloc; 76 #[cfg(feature = "std")] 77 extern crate std; 78 79 mod alphabet; 80 mod decoder; 81 mod encoder; 82 mod encoding; 83 mod errors; 84 mod line_ending; 85 86 #[cfg(test)] 87 mod test_vectors; 88 89 pub use crate::{ 90 alphabet::{ 91 bcrypt::Base64Bcrypt, 92 pbkdf2::Base64Pbkdf2, 93 shacrypt::Base64ShaCrypt, 94 standard::{Base64, Base64Unpadded}, 95 url::{Base64Url, Base64UrlUnpadded}, 96 }, 97 decoder::Decoder, 98 encoder::Encoder, 99 encoding::Encoding, 100 errors::{Error, InvalidEncodingError, InvalidLengthError}, 101 line_ending::LineEnding, 102 }; 103 104 #[allow(deprecated)] 105 pub use crate::alphabet::crypt::Base64Crypt; 106 107 /// Minimum supported line width. 108 const MIN_LINE_WIDTH: usize = 4;