Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hex-literal: remove support for comments inside literals and migrate to CTFE #816

Merged
merged 9 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/hex-literal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
rust:
- 1.45.0 # MSRV
- 1.57.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
strategy:
matrix:
rust:
- 1.45.0 # MSRV
- 1.57.0 # MSRV
- stable
steps:
- uses: actions/checkout@v3
Expand Down
8 changes: 8 additions & 0 deletions hex-literal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## UNRELEASED
### Changed
- Disallow comments inside hex strings ([#816])
- Migrate to 2021 edition and bump MSRV to 1.57 ([#816])
- Use CTFE instead of proc macro ([#816])

[#816]: https://github.com/RustCrypto/utils/pull/816

## 0.3.4 (2021-11-11)
### Changed
- Provide more info in `panic!` messages ([#664])
Expand Down
10 changes: 4 additions & 6 deletions hex-literal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ name = "hex-literal"
version = "0.3.4"
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
description = "Procedural macro for converting hexadecimal string to byte array at compile time."
description = "Macro for converting hexadecimal string to a byte array at compile time"
documentation = "https://docs.rs/hex-literal"
repository = "https://github.com/RustCrypto/utils"
keywords = ["hex", "proc-macro", "literals"]
edition = "2018"

[lib]
proc-macro = true
keywords = ["hex", "literals"]
edition = "2021"
rust-version = "1.57"
84 changes: 84 additions & 0 deletions hex-literal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# [RustCrypto]: hex-literal

[![Crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
![Apache 2.0/MIT Licensed][license-image]
![MSRV][rustc-image]
[![Build Status][build-image]][build-link]

This crate provides the `hex!` macro for converting hexadecimal string literals to a byte array at compile time.

It accepts the following characters in the input string:

- `'0'...'9'`, `'a'...'f'`, `'A'...'F'` — hex characters which will be used in construction of the output byte array
- `' '`, `'\r'`, `'\n'`, `'\t'` — formatting characters which will be ignored

# Examples
```rust
use hex_literal::hex;

// The macro can be used in const contexts
const DATA: [u8; 4] = hex!("01020304");
assert_eq!(DATA, [1, 2, 3, 4]);

// Both upper and lower hex values are supported
assert_eq!(hex!("a1 b2 c3 d4"), [0xA1, 0xB2, 0xC3, 0xD4]);
assert_eq!(hex!("E5 E6 90 92"), [0xE5, 0xE6, 0x90, 0x92]);
assert_eq!(hex!("0a0B 0C0d"), [10, 11, 12, 13]);

// Multi-line literals
let bytes1 = hex!("
00010203 04050607
08090a0b 0c0d0e0f
");
assert_eq!(bytes1, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);

// It's possible to use several literals (results will be concatenated)
let bytes2 = hex!(
"00010203 04050607" // first half
"08090a0b" /* block comment */ "0c0d0e0f" // second half
);
assert_eq!(bytes1, bytes2);
```

Using an unsupported character inside literals will result in a compilation error:
```rust,compile_fail
# use hex_literal::hex;
hex!("АА"); // Cyrillic "А"
hex!("11 22"); // Japanese space
hex!("0123 // Сomments inside literals are not supported");
```

## Minimum Supported Rust Version

Rust **1.57** or newer.

In the future, we reserve the right to change MSRV (i.e. MSRV is out-of-scope for this crate's SemVer guarantees), however when we do it will be accompanied by a minor version bump.

## License

Licensed under either of:

* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
* [MIT license](http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

[//]: # (badges)

[crate-image]: https://img.shields.io/crates/v/hex-literal.svg
[crate-link]: https://crates.io/crates/hex-literal
[docs-image]: https://docs.rs/hex-literal/badge.svg
[docs-link]: https://docs.rs/hex-literal/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg
[build-image]: https://github.com/RustCrypto/utils/actions/workflows/hex-literal.yml/badge.svg
[build-link]: https://github.com/RustCrypto/utils/actions/workflows/hex-literal.yml

[//]: # (general links)

[RustCrypto]: https://github.com/RustCrypto
216 changes: 0 additions & 216 deletions hex-literal/src/comments.rs

This file was deleted.

Loading