pub struct Config<'a> { /* private fields */ }
Expand description
Configuration for Base64 number that consists of
character_set: the characters the Base64 number can have. First character provided is given value 0 and so on until the 64th character which is value 63
pad: Optional padding character for the Base64 number
line_length: Optional maximum line length for the Base64 number
All characters must be graphically representable characters in UTF8
Implements Equals, Debug, and Clone
Implementations§
source§impl<'a> Config<'a>
impl<'a> Config<'a>
sourcepub fn new(
set: &'a [char],
pad_char: Option<char>,
len: Option<u8>
) -> Result<Self, ConfigError>
pub fn new(
set: &'a [char],
pad_char: Option<char>,
len: Option<u8>
) -> Result<Self, ConfigError>
Creates a config with provided values
Parameters:
Character set of the base64 values
Optional: padding for base64
Optional: Fixed line length
Returns:
Result<Self, base64::error::ConfigError> either the new config or an error of: CharacterSetLengthError, NotUniquePaddingError, DuplicateCharacterError, CharacterSetUnrepresentableCharacter, or PaddingUnrepresentableCharacter
Example:
extern crate lb64;
use lb64::config::Config;
fn main() {
let character_set = &[
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
];
match Config::new(character_set, None, None) {
Ok(conf) => println!("Successful"),
Err(e) => println!("{}", e),
}
}
sourcepub fn set_character_set(&mut self, set: &'a [char]) -> Result<(), ConfigError>
pub fn set_character_set(&mut self, set: &'a [char]) -> Result<(), ConfigError>
Sets the character set by the provided slice
Returns:
A Result<(), base64::error::ConfigError> possible ConfigErrors are CharacterSetLengthError, DuplicateCharacterError, or CharacterSetUnrepresentableCharacter
Example:
extern crate lb64;
use lb64::config::Config;
fn main() {
let character_set_orig = &[
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
];
let character_set_new = &[
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_',
];
match Config::new(character_set_orig, None, None) {
Ok(mut conf) => {
match conf.set_character_set(character_set_new) {
Ok(()) => println!("Successful!"), // Since there are no duplicate characters and character_set_new is of length 64 it's successful
Err(e) => println!("{}", e),
}
},
Err(e) => println!("{}", e),
}
}
sourcepub fn get_character_set(&self) -> &[char]
pub fn get_character_set(&self) -> &[char]
Returns the slice of all the characters in the character set
Example:
extern crate lb64;
use lb64::config::MIME;
fn main() {
println!("{:?}", MIME.get_character_set()); // Prints a slice containing [A-Z], [a-z], [0-9], +, and /
}
sourcepub fn get_line_length(&self) -> Option<u8>
pub fn get_line_length(&self) -> Option<u8>
Return Line_length field
Example:
extern crate lb64;
use lb64::config::MIME;
fn main() {
match MIME.get_line_length() {
Some(len) => println!("{}", len), // Prints 76
None => println!("Line length for Mime isn't None"),
}
}
sourcepub fn set_line_length(&mut self, len: Option<u8>)
pub fn set_line_length(&mut self, len: Option<u8>)
Sets the maximum line length for a configuration
Example:
extern crate lb64;
use lb64::config::Config;
use lb64::error::ConfigError;
fn main() {
let character_set = &[
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
];
match Config::new(character_set, None, None) {
Ok(mut conf) => {
conf.set_line_length(Some(5)); // Sets the line_length from None to 5
},
Err(e) => println!("{}", e),
}
}
sourcepub fn get_padding(&self) -> Option<char>
pub fn get_padding(&self) -> Option<char>
Return Padding character
Example:
extern crate lb64;
use lb64::config::MIME;
fn main() {
match MIME.get_padding() {
Some(pad) => println!("{}", pad), // Prints =
None => println!("Padding for Mime isn't None"),
}
}
sourcepub fn set_padding(&mut self, pad_char: Option<char>) -> Result<(), ConfigError>
pub fn set_padding(&mut self, pad_char: Option<char>) -> Result<(), ConfigError>
Sets the padding character
Returns:
Returns a result of <(), base64::error::ConfigError> the ConfigError is either NotUniquePaddingError or PaddingUnrepresentableCharacter
Example:
extern crate lb64;
use lb64::config::Config;
fn main() {
let character_set = &[
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
];
match Config::new(character_set, None, None) {
Ok(mut conf) => {
match conf.set_padding(Some('/')) {
Ok(()) => println!("Set padding character successful!"),
Err(e) => println!("{}", e), // This occurs because / is already taken
}
},
Err(e) => println!("{}", e),
}
}