private void checkConstruction( BiometricData bd, TypeOfBiometricData dataType, AlgorithmIdentifier hashAlgorithm, ASN1OctetString dataHash, DERIA5String dataUri) throws Exception { checkValues(bd, dataType, hashAlgorithm, dataHash, dataUri); bd = BiometricData.getInstance(bd); checkValues(bd, dataType, hashAlgorithm, dataHash, dataUri); ASN1InputStream aIn = new ASN1InputStream(bd.toASN1Object().getEncoded()); ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); bd = BiometricData.getInstance(seq); checkValues(bd, dataType, hashAlgorithm, dataHash, dataUri); }
private void checkValues( BiometricData bd, TypeOfBiometricData dataType, AlgorithmIdentifier algID, ASN1OctetString dataHash, DERIA5String sourceDataURI) { if (!bd.getTypeOfBiometricData().equals(dataType)) { fail("types don't match."); } if (!bd.getHashAlgorithm().equals(algID)) { fail("hash algorithms don't match."); } if (!bd.getBiometricDataHash().equals(dataHash)) { fail("hash algorithms don't match."); } if (sourceDataURI != null) { if (!bd.getSourceDataUri().equals(sourceDataURI)) { fail("data uris don't match."); } } else if (bd.getSourceDataUri() != null) { fail("data uri found when none expected."); } }
private String getBiometricInfoStringValue(byte[] octets) { // @formatter:off /* BiometricSyntax ::= SEQUENCE OF BiometricData BiometricData ::= SEQUENCE { typeOfBiometricData TypeOfBiometricData, hashAlgorithm AlgorithmIdentifier, biometricDataHash OCTET STRING, sourceDataUri IA5String OPTIONAL } TypeOfBiometricData ::= CHOICE { predefinedBiometricType PredefinedBiometricType, biometricDataId OBJECT IDENTIIFER } PredefinedBiometricType ::= INTEGER { picture(0), handwritten-signature(1) } */ // @formatter:on StringBuilder sb = new StringBuilder(); int biometricDataNr = 0; ASN1Sequence asn1Sequence = ASN1Sequence.getInstance(octets); for (ASN1Encodable asn1Encodable : asn1Sequence.toArray()) { BiometricData biometricData = BiometricData.getInstance(asn1Encodable); TypeOfBiometricData typeOfBiometricData = biometricData.getTypeOfBiometricData(); AlgorithmIdentifier hashAlgorithm = biometricData.getHashAlgorithm(); ASN1OctetString biometricDataHash = biometricData.getBiometricDataHash(); DERIA5String sourceDataUri = biometricData.getSourceDataUri(); sb.append(MessageFormat.format(res.getString("BiometricInfo.BiometricData"), biometricDataNr)); sb.append(NEWLINE); sb.append(INDENT); if (typeOfBiometricData.isPredefined()) { int type = typeOfBiometricData.getPredefinedBiometricType(); sb.append(MessageFormat.format(res.getString("BiometricInfo.TypeOfBiometricData"), type)); } else { String biometricDataOid = typeOfBiometricData.getBiometricDataOid().getId(); sb.append(MessageFormat.format(res.getString("BiometricInfo.TypeOfBiometricData"), biometricDataOid)); } sb.append(NEWLINE); sb.append(INDENT); sb.append(MessageFormat.format(res.getString("BiometricInfo.HashAlgorithm"), hashAlgorithm.getAlgorithm().getId())); sb.append(NEWLINE); sb.append(INDENT); sb.append(MessageFormat.format(res.getString("BiometricInfo.BiometricDataHash"), HexUtil.getHexString(biometricDataHash.getOctets()))); sb.append(NEWLINE); if (sourceDataUri != null) { // optional sb.append(INDENT); sb.append(MessageFormat.format(res.getString("BiometricInfo.SourceDataUri"), sourceDataUri.toString())); sb.append(NEWLINE); } } return sb.toString(); }