mirror of https://github.com/apache/nifi.git
NIFI-10764 Fixed handling BIT STRING in nifi-asn1-services
Representing as a string of 1s and 0s (e.g. "010011000") This closes #6622 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
0643f336e8
commit
56d0061da4
|
@ -31,7 +31,7 @@ public class BerBitStringConverter implements JASN1TypeAndValueConverter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataType convertType(Class<?> berType, JASN1Converter converter) {
|
public DataType convertType(Class<?> berType, JASN1Converter converter) {
|
||||||
return RecordFieldType.ARRAY.getArrayDataType(RecordFieldType.BOOLEAN.getDataType());
|
return RecordFieldType.STRING.getDataType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,6 +43,6 @@ public class BerBitStringConverter implements JASN1TypeAndValueConverter {
|
||||||
public Object convertValue(BerType value, DataType dataType, JASN1Converter converter) {
|
public Object convertValue(BerType value, DataType dataType, JASN1Converter converter) {
|
||||||
final BerBitString berValue = (BerBitString) value;
|
final BerBitString berValue = (BerBitString) value;
|
||||||
|
|
||||||
return berValue.getValueAsBooleans();
|
return berValue.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.apache.nifi.jasn1;
|
package org.apache.nifi.jasn1;
|
||||||
|
|
||||||
import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream;
|
import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream;
|
||||||
|
import com.beanit.asn1bean.ber.types.BerBitString;
|
||||||
import com.beanit.asn1bean.ber.types.BerBoolean;
|
import com.beanit.asn1bean.ber.types.BerBoolean;
|
||||||
import com.beanit.asn1bean.ber.types.BerInteger;
|
import com.beanit.asn1bean.ber.types.BerInteger;
|
||||||
import com.beanit.asn1bean.ber.types.BerOctetString;
|
import com.beanit.asn1bean.ber.types.BerOctetString;
|
||||||
|
@ -62,6 +63,7 @@ public class ExampleDataGenerator {
|
||||||
basicTypes.setI(new BerInteger(789));
|
basicTypes.setI(new BerInteger(789));
|
||||||
basicTypes.setOctStr(new BerOctetString(new byte[]{1, 2, 3, 4, 5}));
|
basicTypes.setOctStr(new BerOctetString(new byte[]{1, 2, 3, 4, 5}));
|
||||||
basicTypes.setUtf8Str(new BerUTF8String("Some UTF-8 String. こんにちは世界。"));
|
basicTypes.setUtf8Str(new BerUTF8String("Some UTF-8 String. こんにちは世界。"));
|
||||||
|
basicTypes.setBitStr(new BerBitString(new boolean[]{false, true, true, false, true, false, false, false}));
|
||||||
final int encoded = basicTypes.encode(rev);
|
final int encoded = basicTypes.encode(rev);
|
||||||
out.write(rev.getArray(), 0, encoded);
|
out.write(rev.getArray(), 0, encoded);
|
||||||
LOG.info("Generated {} bytes to {}", encoded, file);
|
LOG.info("Generated {} bytes to {}", encoded, file);
|
||||||
|
|
|
@ -59,6 +59,7 @@ public class TestJASN1RecordReader implements JASN1ReadRecordTester {
|
||||||
assertEquals(789, record.getAsInt("i").intValue());
|
assertEquals(789, record.getAsInt("i").intValue());
|
||||||
assertEquals("0102030405", record.getValue("octStr"));
|
assertEquals("0102030405", record.getValue("octStr"));
|
||||||
assertEquals("Some UTF-8 String. こんにちは世界。", record.getValue("utf8Str"));
|
assertEquals("Some UTF-8 String. こんにちは世界。", record.getValue("utf8Str"));
|
||||||
|
assertEquals("01101000", record.getValue("bitStr"));
|
||||||
|
|
||||||
record = reader.nextRecord(true, false);
|
record = reader.nextRecord(true, false);
|
||||||
assertNull(record);
|
assertNull(record);
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.jasn1;
|
package org.apache.nifi.jasn1;
|
||||||
|
|
||||||
|
import com.beanit.asn1bean.ber.types.BerBitString;
|
||||||
import com.beanit.asn1bean.ber.types.BerBoolean;
|
import com.beanit.asn1bean.ber.types.BerBoolean;
|
||||||
import com.beanit.asn1bean.ber.types.BerInteger;
|
import com.beanit.asn1bean.ber.types.BerInteger;
|
||||||
import com.beanit.asn1bean.ber.types.BerOctetString;
|
import com.beanit.asn1bean.ber.types.BerOctetString;
|
||||||
|
@ -79,19 +80,22 @@ public class TestJASN1RecordReaderWithComplexTypes implements JASN1ReadRecordTes
|
||||||
basicTypes.setI(new BerInteger(789));
|
basicTypes.setI(new BerInteger(789));
|
||||||
basicTypes.setOctStr(new BerOctetString(new byte[]{1, 2, 3, 4, 5}));
|
basicTypes.setOctStr(new BerOctetString(new byte[]{1, 2, 3, 4, 5}));
|
||||||
basicTypes.setUtf8Str(new BerUTF8String("Some UTF-8 String. こんにちは世界。"));
|
basicTypes.setUtf8Str(new BerUTF8String("Some UTF-8 String. こんにちは世界。"));
|
||||||
|
basicTypes.setBitStr(new BerBitString(new boolean[] { true, false, true, true}));
|
||||||
|
|
||||||
Map<String, Object> expectedValues = new HashMap<String, Object>() {{
|
Map<String, Object> expectedValues = new HashMap<String, Object>() {{
|
||||||
put("b", true);
|
put("b", true);
|
||||||
put("i", BigInteger.valueOf(789));
|
put("i", BigInteger.valueOf(789));
|
||||||
put("octStr", "0102030405");
|
put("octStr", "0102030405");
|
||||||
put("utf8Str", "Some UTF-8 String. こんにちは世界。");
|
put("utf8Str", "Some UTF-8 String. こんにちは世界。");
|
||||||
|
put("bitStr", "1011");
|
||||||
}};
|
}};
|
||||||
|
|
||||||
RecordSchema expectedSchema = new SimpleRecordSchema(Arrays.asList(
|
RecordSchema expectedSchema = new SimpleRecordSchema(Arrays.asList(
|
||||||
new RecordField("b", RecordFieldType.BOOLEAN.getDataType()),
|
new RecordField("b", RecordFieldType.BOOLEAN.getDataType()),
|
||||||
new RecordField("i", RecordFieldType.BIGINT.getDataType()),
|
new RecordField("i", RecordFieldType.BIGINT.getDataType()),
|
||||||
new RecordField("octStr", RecordFieldType.STRING.getDataType()),
|
new RecordField("octStr", RecordFieldType.STRING.getDataType()),
|
||||||
new RecordField("utf8Str", RecordFieldType.STRING.getDataType())
|
new RecordField("utf8Str", RecordFieldType.STRING.getDataType()),
|
||||||
|
new RecordField("bitStr", RecordFieldType.STRING.getDataType())
|
||||||
));
|
));
|
||||||
|
|
||||||
testReadRecord(dataFile, basicTypes, expectedValues, expectedSchema);
|
testReadRecord(dataFile, basicTypes, expectedValues, expectedSchema);
|
||||||
|
@ -156,7 +160,8 @@ public class TestJASN1RecordReaderWithComplexTypes implements JASN1ReadRecordTes
|
||||||
new RecordField("b", RecordFieldType.BOOLEAN.getDataType()),
|
new RecordField("b", RecordFieldType.BOOLEAN.getDataType()),
|
||||||
new RecordField("i", RecordFieldType.BIGINT.getDataType()),
|
new RecordField("i", RecordFieldType.BIGINT.getDataType()),
|
||||||
new RecordField("octStr", RecordFieldType.STRING.getDataType()),
|
new RecordField("octStr", RecordFieldType.STRING.getDataType()),
|
||||||
new RecordField("utf8Str", RecordFieldType.STRING.getDataType())
|
new RecordField("utf8Str", RecordFieldType.STRING.getDataType()),
|
||||||
|
new RecordField("bitStr", RecordFieldType.STRING.getDataType())
|
||||||
));
|
));
|
||||||
|
|
||||||
RecordSchema expectedSchema = new SimpleRecordSchema(Arrays.asList(
|
RecordSchema expectedSchema = new SimpleRecordSchema(Arrays.asList(
|
||||||
|
|
|
@ -106,11 +106,11 @@ public class TestJASN1RecordReaderWithSimpleTypes implements JASN1ReadRecordTest
|
||||||
berValue.setValue(new BerBitString(new boolean[]{false, true, false, false, true, true, true, true, false, true, false, false}));
|
berValue.setValue(new BerBitString(new boolean[]{false, true, false, false, true, true, true, true, false, true, false, false}));
|
||||||
|
|
||||||
Map<String, Object> expectedValues = new HashMap<String, Object>() {{
|
Map<String, Object> expectedValues = new HashMap<String, Object>() {{
|
||||||
put("value", new boolean[]{false, true, false, false, true, true, true, true, false, true, false, false});
|
put("value", "010011110100");
|
||||||
}};
|
}};
|
||||||
|
|
||||||
RecordSchema expectedSchema = new SimpleRecordSchema(Arrays.asList(
|
RecordSchema expectedSchema = new SimpleRecordSchema(Arrays.asList(
|
||||||
new RecordField("value", RecordFieldType.ARRAY.getArrayDataType(RecordFieldType.BOOLEAN.getDataType())))
|
new RecordField("value", RecordFieldType.STRING.getDataType()))
|
||||||
);
|
);
|
||||||
|
|
||||||
testReadRecord(dataFile, berValue, expectedValues, expectedSchema);
|
testReadRecord(dataFile, berValue, expectedValues, expectedSchema);
|
||||||
|
|
|
@ -13,7 +13,8 @@ BasicTypes ::= SEQUENCE
|
||||||
b [0] BOOLEAN,
|
b [0] BOOLEAN,
|
||||||
i [1] INTEGER,
|
i [1] INTEGER,
|
||||||
octStr [2] OCTET STRING (SIZE (1..10)),
|
octStr [2] OCTET STRING (SIZE (1..10)),
|
||||||
utf8Str [3] UTF8String OPTIONAL
|
utf8Str [3] UTF8String OPTIONAL,
|
||||||
|
bitStr [4] BIT STRING OPTIONAL
|
||||||
}
|
}
|
||||||
|
|
||||||
Composite ::= SEQUENCE
|
Composite ::= SEQUENCE
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue