List of usage examples for org.bouncycastle.asn1.cmp PKIFreeText size
public int size()
From source file:com.guardtime.asn1.StatusInfo.java
License:Apache License
/** * Class constructor./*from www . j av a2 s . c o m*/ * * @param obj DER-encoded status info object. * * @throws Asn1FormatException if status info object has invalid format. */ StatusInfo(ASN1Encodable obj) throws Asn1FormatException { try { statusInfo = PKIStatusInfo.getInstance(obj); statusCode = statusInfo.getStatus().intValue(); // RFC 3161: // // Compliant servers SHOULD NOT produce any other (than 0..5) // values. Compliant clients MUST generate an error // if values it does not understand are present. if (statusCode < 0 || statusCode > 5) { throw new Asn1FormatException("invalid status: " + statusCode); } PKIFreeText freeText = statusInfo.getStatusString(); if (freeText != null) { int freeTextSize = freeText.size(); // PKIFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String if (freeTextSize < 1) { throw new Asn1FormatException("zero-length status string not allowed"); } statusText = new ArrayList(); for (int i = 0; i < freeTextSize; i++) { statusText.add(freeText.getStringAt(i).getString()); } } // -1 means that status code is not set failCode = -1; DERBitString bitString = statusInfo.getFailInfo(); if (bitString != null) { byte[] failBytes = bitString.getBytes(); int len = failBytes.length * 8; for (int i = 0; i < len; i++) { // return only the first error encountered if ((failBytes[i >> 3] & (0x80 >> (i & 7))) != 0) { failCode = i; break; } } // Check that received fail code is valid boolean isValidFailCode = false; for (int i = 0; i < allowedFailCodes.length; i++) { if (failCode == allowedFailCodes[i]) { isValidFailCode = true; break; } } if (!isValidFailCode) { throw new Asn1FormatException("invalid fail info: " + failCode); } } } catch (Asn1FormatException e) { throw e; } catch (Exception e) { throw new Asn1FormatException("status info has invalid format", e); } }
From source file:ee.ria.xroad.proxy.messagelog.TimestamperUtil.java
License:Open Source License
static TimeStampResponse getTimestampResponse(InputStream in) throws Exception { TimeStampResp response = TimeStampResp.getInstance(new ASN1InputStream(in).readObject()); if (response == null) { throw new RuntimeException("Could not read time-stamp response"); }// w ww. jav a 2 s . co m BigInteger status = response.getStatus().getStatus(); log.trace("getTimestampDer() - TimeStampResp.status: {}", status); if (!PKIStatus.granted.getValue().equals(status) && !PKIStatus.grantedWithMods.getValue().equals(status)) { PKIFreeText statusString = response.getStatus().getStatusString(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < statusString.size(); i++) { if (i > 0) { sb.append(", "); } sb.append("\"" + statusString.getStringAt(i) + "\""); } log.error("getTimestampDer() - TimeStampResp.status is not " + "\"granted\" neither \"grantedWithMods\": {}, {}", status, sb); throw new RuntimeException("TimeStampResp.status: " + status + ", .statusString: " + sb); } return new TimeStampResponse(response); }