diff --git a/R/tsp.R b/R/tsp.R index dd19d59..93dbb9f 100644 --- a/R/tsp.R +++ b/R/tsp.R @@ -12,14 +12,21 @@ get_timestamp_secure <- function(tsq) { if(resp$status_code == 200L) { tsr <- PKI::ASN1.decode(resp$body) - ts <- PKI::ASN1.decode(PKI::ASN1.decode(PKI::ASN1.decode(tsr[[2]][[2]])[[3]][[2]]))[[5]] - ts <- as.POSIXct(rawToChar(ts), format = "%Y%m%d%H%M%SZ", tz="UTC") + if (tsr[[1]][[1]] == 0) { + # PKIStatus ::= INTEGER { granted (0), grantedWithMods (1), rejection (2), waiting (3), + # revocationWarning (4), revocationNotification (5) } + ts <- PKI::ASN1.decode(PKI::ASN1.decode(PKI::ASN1.decode(tsr[[2]][[2]])[[3]][[2]]))[[5]] + ts <- as.POSIXct(rawToChar(ts), format = "%Y%m%d%H%M%SZ", tz="UTC") - out <- list(ts = structure(strftime(ts, "%Y-%m-%dT%H:%M:%SZ", tz="UTC"), - unix_ts = as.integer(ts), - class = "pqcrypto_timestamp"), - tsr = structure(resp$body, - class = "pqcrypto_tsp_tsr")) + out <- list(ts = structure(strftime(ts, "%Y-%m-%dT%H:%M:%SZ", tz="UTC"), + unix_ts = as.integer(ts), + class = "pqcrypto_timestamp"), + tsr = structure(resp$body, + class = "pqcrypto_tsp_tsr")) + } else { + out <- list(ts = get_timestamp(), + tsr = NULL) + } } else { out <- list(ts = get_timestamp(), tsr = NULL)