Struct x509_parser::certificate::Validity
source · pub struct Validity {
pub not_before: ASN1Time,
pub not_after: ASN1Time,
}
Fields§
§not_before: ASN1Time
§not_after: ASN1Time
Implementations§
source§impl Validity
impl Validity
sourcepub fn time_to_expiration(&self) -> Option<Duration>
pub fn time_to_expiration(&self) -> Option<Duration>
The time left before the certificate expires.
If the certificate is not currently valid, then None
is
returned. Otherwise, the Duration
until the certificate
expires is returned.
sourcepub fn is_valid_at(&self, time: ASN1Time) -> bool
pub fn is_valid_at(&self, time: ASN1Time) -> bool
Check the certificate time validity for the provided date/time
sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Check the certificate time validity
Examples found in repository?
examples/print-cert.rs (line 168)
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
fn print_x509_info(x509: &X509Certificate) -> io::Result<()> {
let version = x509.version();
if version.0 < 3 {
println!(" Version: {}", version);
} else {
println!(" Version: INVALID({})", version.0);
}
println!(" Serial: {}", x509.tbs_certificate.raw_serial_as_string());
println!(" Subject: {}", x509.subject());
println!(" Issuer: {}", x509.issuer());
println!(" Validity:");
println!(" NotBefore: {}", x509.validity().not_before);
println!(" NotAfter: {}", x509.validity().not_after);
println!(" is_valid: {}", x509.validity().is_valid());
println!(" Subject Public Key Info:");
print_x509_ski(x509.public_key());
print_x509_signature_algorithm(&x509.signature_algorithm, 4);
println!(" Signature Value:");
for l in format_number_to_hex_with_colon(&x509.signature_value.data, 16) {
println!(" {}", l);
}
println!(" Extensions:");
for ext in x509.extensions() {
print_x509_extension(&ext.oid, ext);
}
println!();
print!("Structure validation status: ");
#[cfg(feature = "validate")]
{
let mut logger = VecLogger::default();
// structure validation status
let ok = X509StructureValidator
.chain(X509CertificateValidator)
.validate(x509, &mut logger);
if ok {
println!("Ok");
} else {
println!("FAIL");
}
for warning in logger.warnings() {
println!(" [W] {}", warning);
}
for error in logger.errors() {
println!(" [E] {}", error);
}
println!();
if VALIDATE_ERRORS_FATAL && !logger.errors().is_empty() {
return Err(io::Error::new(io::ErrorKind::Other, "validation failed"));
}
}
#[cfg(not(feature = "validate"))]
{
println!("Unknown (feature 'validate' not enabled)");
}
#[cfg(feature = "verify")]
{
print!("Signature verification: ");
if x509.subject() == x509.issuer() {
if x509.verify_signature(None).is_ok() {
println!("OK");
println!(" [I] certificate is self-signed");
} else if x509.subject() == x509.issuer() {
println!("FAIL");
println!(" [W] certificate looks self-signed, but signature verification failed");
}
} else {
// if subject is different from issuer, we cannot verify certificate without the public key of the issuer
println!("N/A");
}
}
Ok(())
}
Trait Implementations§
source§impl<'a> FromDer<'a, X509Error> for Validity
impl<'a> FromDer<'a, X509Error> for Validity
source§fn from_der(i: &[u8]) -> X509Result<'_, Self>
fn from_der(i: &[u8]) -> X509Result<'_, Self>
Attempt to parse input bytes into a DER object (enforcing constraints)
source§impl PartialEq for Validity
impl PartialEq for Validity
impl Eq for Validity
impl StructuralPartialEq for Validity
Auto Trait Implementations§
impl RefUnwindSafe for Validity
impl Send for Validity
impl Sync for Validity
impl Unpin for Validity
impl UnwindSafe for Validity
Blanket Implementations§
source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more