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

const-oid: leverage const_panic; MSRV 1.57 #341

Merged
merged 1 commit into from
Jan 18, 2022
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/const-oid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
rust:
- 1.56.0 # MSRV
- 1.57.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
Expand All @@ -42,7 +42,7 @@ jobs:
strategy:
matrix:
rust:
- 1.56.0 # MSRV
- 1.57.0 # MSRV
- stable
steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions const-oid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "const-oid"
version = "0.7.1"
version = "0.8.0-pre"
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
description = """
Expand All @@ -14,7 +14,7 @@ categories = ["cryptography", "data-structures", "encoding", "no-std", "parser-i
keywords = ["iso", "iec", "itu", "oid"]
readme = "README.md"
edition = "2021"
rust-version = "1.56"
rust-version = "1.57"

[dev-dependencies]
hex-literal = "0.3"
Expand Down
4 changes: 2 additions & 2 deletions const-oid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ well as a runtime OID library.

## Minimum Supported Rust Version

This crate requires **Rust 1.56** at a minimum.
This crate requires **Rust 1.57** at a minimum.

We may change the MSRV in the future, but it will be accompanied by a minor
version bump.
Expand All @@ -84,7 +84,7 @@ dual licensed as above, without any additional terms or conditions.
[docs-image]: https://docs.rs/const-oid/badge.svg
[docs-link]: https://docs.rs/const-oid/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.56+-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.57+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/300570-formats
[build-image]: https://github.com/RustCrypto/formats/workflows/const-oid/badge.svg?branch=master&event=push
Expand Down
10 changes: 5 additions & 5 deletions const-oid/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ impl Encoder {
pub(crate) const fn encode(mut self, arc: Arc) -> Self {
match self.state {
State::Initial => {
const_assert!(arc <= ARC_MAX_FIRST, "invalid first arc (must be 0-2)");
assert!(arc <= ARC_MAX_FIRST, "invalid first arc (must be 0-2)");
self.state = State::FirstArc(arc);
self
}
State::FirstArc(first_arc) => {
const_assert!(arc <= ARC_MAX_SECOND, "invalid second arc (must be 0-39)");
assert!(arc <= ARC_MAX_SECOND, "invalid second arc (must be 0-39)");
self.state = State::Body;
self.bytes[0] = (first_arc * (ARC_MAX_SECOND + 1)) as u8 + arc as u8;
self.cursor = 1;
Expand All @@ -58,7 +58,7 @@ impl Encoder {
// Total number of bytes in encoded arc - 1
let nbytes = base128_len(arc);

const_assert!(
assert!(
self.cursor + nbytes + 1 < ObjectIdentifier::MAX_SIZE,
"OID too long (exceeded max DER bytes)"
);
Expand All @@ -73,7 +73,7 @@ impl Encoder {

/// Finish encoding an OID
pub(crate) const fn finish(self) -> ObjectIdentifier {
const_assert!(self.cursor >= 2, "OID too short (minimum 3 arcs)");
assert!(self.cursor >= 2, "OID too short (minimum 3 arcs)");
ObjectIdentifier {
bytes: self.bytes,
length: self.cursor as u8,
Expand All @@ -88,7 +88,7 @@ impl Encoder {
self.bytes[self.cursor + i] = (n & 0b1111111) as u8 | mask;
n >>= 7;

const_assert!(i > 0, "Base 128 offset miscalculation");
assert!(i > 0, "Base 128 offset miscalculation");
self.encode_base128_byte(n, i.saturating_sub(1), true)
} else {
self.bytes[self.cursor] = n as u8 | mask;
Expand Down
5 changes: 1 addition & 4 deletions const-oid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
html_root_url = "https://docs.rs/const-oid/0.7.1"
html_root_url = "https://docs.rs/const-oid/0.8.0-pre"
)]
#![forbid(unsafe_code, clippy::unwrap_used)]
#![warn(missing_docs, rust_2018_idioms)]

#[cfg(feature = "std")]
extern crate std;

#[macro_use]
mod macros;

mod arcs;
mod encoder;
mod error;
Expand Down
10 changes: 0 additions & 10 deletions const-oid/src/macros.rs

This file was deleted.

10 changes: 5 additions & 5 deletions const-oid/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ impl Parser {
/// Parse an OID from a dot-delimited string e.g. `1.2.840.113549.1.1.1`
pub(crate) const fn parse(s: &str) -> Self {
let bytes = s.as_bytes();
const_assert!(!bytes.is_empty(), "OID string is empty");
const_assert!(
assert!(!bytes.is_empty(), "OID string is empty");
assert!(
matches!(bytes[0], b'0'..=b'9'),
"OID must start with a digit"
);
Expand Down Expand Up @@ -50,18 +50,18 @@ impl Parser {
self.parse_bytes(remaining)
}
[b'.', remaining @ ..] => {
const_assert!(!remaining.is_empty(), "invalid trailing '.' in OID");
assert!(!remaining.is_empty(), "invalid trailing '.' in OID");
self.encoder = self.encoder.encode(self.current_arc);
self.current_arc = 0;
self.parse_bytes(remaining)
}
[byte, ..] => {
const_assert!(
assert!(
matches!(byte, b'0'..=b'9' | b'.'),
"invalid character in OID"
);

// Unreachable (checked by above `const_assert!`)
// Unreachable (checked by above `assert!`)
// Needed for match exhaustiveness and matching types
self
}
Expand Down
2 changes: 1 addition & 1 deletion der/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ edition = "2021"
rust-version = "1.57"

[dependencies]
const-oid = { version = "0.7", optional = true, path = "../const-oid" }
const-oid = { version = "=0.8.0-pre", optional = true, path = "../const-oid" }
crypto-bigint = { version = "=0.4.0-pre", optional = true, default-features = false, features = ["generic-array"] }
der_derive = { version = "0.5", optional = true, path = "derive" }
pem-rfc7468 = { version = "0.3", optional = true, path = "../pem-rfc7468" }
Expand Down