Skip to content
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
3 changes: 1 addition & 2 deletions x509-cert/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ pub enum Error {
MissingAttributes,
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}
impl core::error::Error for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
13 changes: 6 additions & 7 deletions x509-cert/src/ext/pkix/name/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,18 @@ pub enum GeneralName {
RegisteredId(ObjectIdentifier),
}

#[cfg(feature = "std")]
impl From<std::net::IpAddr> for GeneralName {
fn from(ip: std::net::IpAddr) -> Self {
impl From<core::net::IpAddr> for GeneralName {
fn from(ip: core::net::IpAddr) -> Self {
// Safety: this is unfailable here, OctetString will issue an error if you go
// over 256MiB, here the buffer is at most 16 bytes (ipv6). The two `expect`s
// below are safe.
let buf = match ip {
std::net::IpAddr::V4(v) => {
core::net::IpAddr::V4(v) => {
let value = v.octets();
OctetString::new(&value[..])
.expect("OctetString is not expected to fail with a 4 bytes long buffer")
}
std::net::IpAddr::V6(v) => {
core::net::IpAddr::V6(v) => {
let value = v.octets();
OctetString::new(&value[..])
.expect("OctetString is not expected to fail with a 16 bytes long buffer")
Expand All @@ -85,15 +84,15 @@ impl From<std::net::IpAddr> for GeneralName {
}
}

#[cfg(all(feature = "std", test))]
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
use der::Encode;

#[test]
fn test_convert() {
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use core::net::{IpAddr, Ipv4Addr, Ipv6Addr};

let localhost_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
let localhost_v6 = IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1));
Expand Down
3 changes: 3 additions & 0 deletions x509-cert/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
)]
#![forbid(unsafe_code)]
#![warn(
clippy::alloc_instead_of_core,
clippy::mod_module_files,
clippy::std_instead_of_alloc,
clippy::std_instead_of_core,
clippy::unwrap_used,
missing_docs,
rust_2018_idioms,
Expand Down