data-encoding-macro-0.1.7/Cargo.toml.orig010064000017500001750000000014601345743445500164360ustar0000000000000000[package] name = "data-encoding-macro" version = "0.1.7" authors = ["Julien Cretin "] license = "MIT" edition = "2018" keywords = ["data-encoding", "macro", "static", "const", "compile-time"] categories = ["encoding"] readme = "README.md" repository = "https://github.com/ia0/data-encoding" documentation = "https://docs.rs/data-encoding-macro" description = "Macros for data-encoding" include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"] [package.metadata.docs.rs] no-default-features = true [features] default = ["stable"] stable = ["data-encoding-macro-internal/stable", "proc-macro-hack"] [dependencies] data-encoding = { version = "2.1", path = ".." } data-encoding-macro-internal = { version = "0.1.7", path = "internal" } proc-macro-hack = { version = "0.5", optional = true } data-encoding-macro-0.1.7/Cargo.toml0000644000000024500000000000000126730ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "data-encoding-macro" version = "0.1.7" authors = ["Julien Cretin "] include = ["Cargo.toml", "LICENSE", "README.md", "src/lib.rs"] description = "Macros for data-encoding" documentation = "https://docs.rs/data-encoding-macro" readme = "README.md" keywords = ["data-encoding", "macro", "static", "const", "compile-time"] categories = ["encoding"] license = "MIT" repository = "https://github.com/ia0/data-encoding" [package.metadata.docs.rs] no-default-features = true [dependencies.data-encoding] version = "2.1" [dependencies.data-encoding-macro-internal] version = "0.1.7" [dependencies.proc-macro-hack] version = "0.5" optional = true [features] default = ["stable"] stable = ["data-encoding-macro-internal/stable", "proc-macro-hack"] data-encoding-macro-0.1.7/LICENSE010064000017500001750000000021341341316441000145320ustar0000000000000000The MIT License (MIT) Copyright (c) 2015-2017 Julien Cretin Copyright (c) 2017 Google Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. data-encoding-macro-0.1.7/README.md010064000017500001750000000030731345743445500150300ustar0000000000000000This library provides macros to define compile-time byte slices and arrays from encoded strings (using common bases like base64, base32, or hexadecimal, and also custom bases). It also provides a macro to define compile-time custom encodings to be used with the [data-encoding] crate. If you were familiar with the [binary_macros] crate, this library is actually [inspired][binary_macros_issue] from it. If you use a nightly compiler, you may disable the "stable" feature: ``` data-encoding-macro = { version = "0.1", default-features = false } ``` ### Examples You can define a compile-time byte slice or array (using the `hexlower` or `base64` macros for example): ```rust const HELLO: &'static [u8] = &hexlower!("68656c6c6f"); const FOOBAR: &'static [u8] = &base64!("Zm9vYmFy"); // In nightly, it is possible to define an array instead of a slice: hexlower_array!("const HELLO" = "68656c6c6f"); base64_array!("const FOOBAR" = "Zm9vYmFy"); ``` You can define a compile-time custom encoding using the `new_encoding` macro: ```rust const HEX: Encoding = new_encoding!{ symbols: "0123456789abcdef", translate_from: "ABCDEF", translate_to: "abcdef", }; const BASE64: Encoding = new_encoding!{ symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", padding: '=', }; ``` See the [documentation] for more details. [binary_macros]: https://crates.io/crates/binary_macros [binary_macros_issue]: https://github.com/ia0/data-encoding/issues/7 [data-encoding]: https://crates.io/crates/data-encoding [documentation]: https://docs.rs/data-encoding-macro data-encoding-macro-0.1.7/src/lib.rs010064000017500001750000000261351345743445500154600ustar0000000000000000//! Macros for data-encoding //! //! This library provides macros to define compile-time byte arrays from encoded //! strings (using common bases like [base64], [base32], or [hexadecimal], and //! also custom bases). It also provides a macro to define compile-time custom //! encodings to be used with the [data-encoding] crate at run-time. //! //! If you were familiar with the [binary_macros] crate, this library is //! actually [inspired][binary_macros_issue] from it. //! //! If you use a nightly compiler, you may disable the "stable" feature: //! //! ```text //! data-encoding-macro = { version = "0.1", default-features = false } //! ``` //! //! # Examples //! //! You can define a compile-time byte slice from an encoded string literal: //! //! ```rust //! # #![cfg_attr(not(feature = "stable"), feature(proc_macro_hygiene))] //! #[macro_use] //! extern crate data_encoding_macro; //! //! const HELLO_SLICE: &'static [u8] = &hexlower!("68656c6c6f"); //! const FOOBAR_SLICE: &'static [u8] = &base64!("Zm9vYmFy"); //! # fn main() {} //! ``` //! //! When you disable the "stable" feature (and use a nightly compiler), you can //! also define a compile-time byte array from an encoded string literal: //! //! ```rust //! # #[macro_use] extern crate data_encoding_macro; //! # #[cfg(not(feature = "stable"))] //! hexlower_array!("const HELLO" = "68656c6c6f"); //! # #[cfg(not(feature = "stable"))] //! base64_array!("const FOOBAR" = "Zm9vYmFy"); //! # fn main() {} //! ``` //! //! You can define a compile-time custom encoding from its specification: //! //! ```rust //! # #![cfg_attr(not(feature = "stable"), feature(proc_macro_hygiene))] //! extern crate data_encoding; //! #[macro_use] //! extern crate data_encoding_macro; //! use data_encoding::Encoding; //! //! const HEX: Encoding = new_encoding! { //! symbols: "0123456789abcdef", //! translate_from: "ABCDEF", //! translate_to: "abcdef", //! }; //! const BASE64: Encoding = new_encoding! { //! symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", //! padding: '=', //! }; //! # fn main() {} //! ``` //! //! [base32]: macro.base32.html //! [base64]: macro.base64.html //! [binary_macros]: https://crates.io/crates/binary_macros //! [binary_macros_issue]: https://github.com/ia0/data-encoding/issues/7 //! [data-encoding]: https://crates.io/crates/data-encoding //! [hexadecimal]: macro.hexlower_permissive.html #![cfg_attr(not(feature = "stable"), feature(proc_macro_hygiene))] #![warn(unused_results)] #[cfg(feature = "stable")] extern crate proc_macro_hack; extern crate data_encoding; extern crate data_encoding_macro_internal; #[cfg(feature = "stable")] use proc_macro_hack::proc_macro_hack; #[cfg(not(feature = "stable"))] #[doc(hidden)] pub use data_encoding_macro_internal::*; #[cfg(feature = "stable")] #[proc_macro_hack] #[doc(hidden)] pub use data_encoding_macro_internal::internal_new_encoding; #[cfg(feature = "stable")] #[proc_macro_hack] #[doc(hidden)] pub use data_encoding_macro_internal::internal_decode_slice; /// Defines a compile-time byte array by decoding a string literal /// /// This macro takes a list of `key: value,` pairs (the last comma is required). /// It takes the key-value pairs specifying the encoding to use to decode the /// input (see [new_encoding] for the possible key-value pairs), the input /// itself keyed by `input`, and the output keyed by `name`. The output must be /// of the form `[pub] {const|static} `. /// /// # Examples /// /// ```rust /// #[macro_use] /// extern crate data_encoding_macro; /// /// decode_array! { /// name: "const OCTAL", /// symbols: "01234567", /// padding: '=', /// input: "237610==", /// } /// # fn main() {} /// ``` /// /// [new_encoding]: macro.new_encoding.html #[cfg(not(feature = "stable"))] #[macro_export] macro_rules! decode_array { ($($arg: tt)*) => { $crate::internal_decode_array!($($arg)*); }; } /// Defines a compile-time byte slice by decoding a string literal /// /// This macro takes a list of `key: value,` pairs (the last comma is required). /// It takes the key-value pairs specifying the encoding to use to decode the /// input (see [new_encoding] for the possible key-value pairs), the input /// itself keyed by `input`, and the output keyed by `name`. /// /// # Examples /// /// ```rust /// # #![feature(proc_macro_hygiene)] /// #[macro_use] /// extern crate data_encoding_macro; /// /// const OCTAL: &'static [u8] = &decode_slice! { /// symbols: "01234567", /// padding: '=', /// input: "237610==", /// }; /// # fn main() {} /// ``` /// /// [new_encoding]: macro.new_encoding.html #[cfg(not(feature = "stable"))] #[macro_export] macro_rules! decode_slice { ($($arg: tt)*) => { $crate::internal_decode_slice!($($arg)*) }; } /// Defines a compile-time byte slice by decoding a string literal /// /// This macro takes a list of `key: value,` pairs (the last comma is required). /// It takes the key-value pairs specifying the encoding to use to decode the /// input (see [new_encoding] for the possible key-value pairs), the input /// itself keyed by `input`, and the output keyed by `name`. /// /// # Examples /// /// ```rust /// #[macro_use] /// extern crate data_encoding_macro; /// /// const OCTAL: &'static [u8] = &decode_slice! { /// symbols: "01234567", /// padding: '=', /// input: "237610==", /// }; /// # fn main() {} /// ``` /// /// [new_encoding]: macro.new_encoding.html #[cfg(feature = "stable")] #[macro_export] macro_rules! decode_slice { ($($arg: tt)*) => { internal_decode_slice!($($arg)*) }; } /// Defines a compile-time custom encoding /// /// This macro takes a list of `key: value,` pairs (the last comma is required). /// The possible key-value pairs are: /// /// ```text /// symbols: , // e.g. "01234567" /// padding: [None]|, // e.g. '=' /// bit_order: [MostSignificantFirst]|LeastSignificantFirst, /// check_trailing_bits: [true]|false, /// ignore: [""]|, // e.g. " \t\n" /// wrap_width: [0]|, // e.g. 76 /// wrap_separator: [""]|, // e.g. "\r\n" /// translate_from: [""]|, // e.g. "ABCDEF" /// translate_to: [""]|, // e.g. "abcdef" /// ``` /// /// Only `symbols` is required. Everything else is optional and defaults to the /// value between square brackets. /// /// # Examples /// /// ```rust /// # #![feature(proc_macro_hygiene)] /// extern crate data_encoding; /// #[macro_use] /// extern crate data_encoding_macro; /// /// const HEX: data_encoding::Encoding = new_encoding! { /// symbols: "0123456789abcdef", /// ignore: " \r\t\n", /// wrap_width: 32, /// wrap_separator: "\n", /// translate_from: "ABCDEF", /// translate_to: "abcdef", /// }; /// # fn main() {} /// ``` #[cfg(not(feature = "stable"))] #[macro_export] macro_rules! new_encoding { ($($arg: tt)*) => { ::data_encoding::Encoding(::std::borrow::Cow::Borrowed( &$crate::internal_new_encoding!{ $($arg)* })) }; } /// Defines a compile-time custom encoding /// /// This macro takes a list of `key: value,` pairs (the last comma is required). /// The possible key-value pairs are: /// /// ```text /// symbols: , // e.g. "01234567" /// padding: [None]|, // e.g. '=' /// bit_order: [MostSignificantFirst]|LeastSignificantFirst, /// check_trailing_bits: [true]|false, /// ignore: [""]|, // e.g. " \t\n" /// wrap_width: [0]|, // e.g. 76 /// wrap_separator: [""]|, // e.g. "\r\n" /// translate_from: [""]|, // e.g. "ABCDEF" /// translate_to: [""]|, // e.g. "abcdef" /// ``` /// /// Only `symbols` is required. Everything else is optional and defaults to the /// value between square brackets. /// /// # Examples /// /// ```rust /// extern crate data_encoding; /// #[macro_use] /// extern crate data_encoding_macro; /// /// const HEX: data_encoding::Encoding = new_encoding! { /// symbols: "0123456789abcdef", /// ignore: " \r\t\n", /// wrap_width: 32, /// wrap_separator: "\n", /// translate_from: "ABCDEF", /// translate_to: "abcdef", /// }; /// # fn main() {} /// ``` #[cfg(feature = "stable")] #[macro_export] macro_rules! new_encoding { ($($arg: tt)*) => { ::data_encoding::Encoding(::std::borrow::Cow::Borrowed( &internal_new_encoding!{ $($arg)* })) }; } macro_rules! make { ($base: ident $base_array: ident = $ref: ident; $($spec: tt)*) => { #[cfg(not(feature = "stable"))] #[macro_export] macro_rules! $base_array { ($n: tt = $x: tt) => { decode_array!(name: $n, input: $x, $($spec)*); }; } #[macro_export] macro_rules! $base { ($x: tt) => { decode_slice!(input: $x, $($spec)*) }; } #[test] fn $base() { assert_eq!(new_encoding!($($spec)*), data_encoding::$ref); } }; } make! { hexlower hexlower_array = HEXLOWER; symbols: "0123456789abcdef", } make! { hexlower_permissive hexlower_permissive_array = HEXLOWER_PERMISSIVE; symbols: "0123456789abcdef", translate_from: "ABCDEF", translate_to: "abcdef", } make! { hexupper hexupper_array = HEXUPPER; symbols: "0123456789ABCDEF", } make! { hexupper_permissive hexupper_permissive_array = HEXUPPER_PERMISSIVE; symbols: "0123456789ABCDEF", translate_from: "abcdef", translate_to: "ABCDEF", } make! { base32 base32_array = BASE32; symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", padding: '=', } make! { base32_nopad base32_nopad_array = BASE32_NOPAD; symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", } make! { base32hex base32hex_array = BASE32HEX; symbols: "0123456789ABCDEFGHIJKLMNOPQRSTUV", padding: '=', } make! { base32hex_nopad base32hex_nopad_array = BASE32HEX_NOPAD; symbols: "0123456789ABCDEFGHIJKLMNOPQRSTUV", } make! { base32_dnssec base32_dnssec_array = BASE32_DNSSEC; symbols: "0123456789abcdefghijklmnopqrstuv", translate_from: "ABCDEFGHIJKLMNOPQRSTUV", translate_to: "abcdefghijklmnopqrstuv", } make! { base32_dnscurve base32_dnscurve_array = BASE32_DNSCURVE; symbols: "0123456789bcdfghjklmnpqrstuvwxyz", bit_order: LeastSignificantFirst, translate_from: "BCDFGHJKLMNPQRSTUVWXYZ", translate_to: "bcdfghjklmnpqrstuvwxyz", } make! { base64 base64_array = BASE64; symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", padding: '=', } make! { base64_nopad base64_nopad_array = BASE64_NOPAD; symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", } make! { base64_mime base64_mime_array = BASE64_MIME; symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", padding: '=', wrap_width: 76, wrap_separator: "\r\n", } make! { base64url base64url_array = BASE64URL; symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", padding: '=', } make! { base64url_nopad base64url_nopad_array = BASE64URL_NOPAD; symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", } data-encoding-macro-0.1.7/.cargo_vcs_info.json0000644000000001120000000000000146660ustar00{ "git": { "sha1": "cda5148da701c837b7bdc0aa9b5096823de2f3ac" } }