本文整理汇总了Java中co.nstant.in.cbor.model.DataItem类的典型用法代码示例。如果您正苦于以下问题:Java DataItem类的具体用法?Java DataItem怎么用?Java DataItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataItem类属于co.nstant.in.cbor.model包,在下文中一共展示了DataItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
@Override
DataItem encode() throws CborException {
Map result = new Map();
if (attestnCert != null) {
Array x5c = new Array();
x5c.add(new ByteString(attestnCert));
for (byte[] cert : this.caCert) {
x5c.add(new ByteString(cert));
}
result.put(new UnicodeString("x5c"), x5c);
}
if (ecdaaKeyId != null) {
result.put(new UnicodeString("ecdaaKeyId"), new ByteString(ecdaaKeyId));
}
result.put(new UnicodeString("sig"), new ByteString(sig));
result.put(new UnicodeString("alg"), new UnicodeString(alg.toString()));
return result;
}
示例2: decode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
/**
* Decodes a cbor representation of an AndroidSafetyNetAttestationStatement into the object
* representation
*
* @param attStmt Cbor DataItem representation of the attestation statement to decode
* @return Decoded AndroidSafetyNetAttestationStatement
* @throws ResponseException Input was not a valid AndroidSafetyNetAttestationStatement DataItem
*/
public static AndroidSafetyNetAttestationStatement decode(DataItem attStmt)
throws ResponseException {
AndroidSafetyNetAttestationStatement result = new AndroidSafetyNetAttestationStatement();
Map given = (Map) attStmt;
for (DataItem data : given.getKeys()) {
if (data instanceof UnicodeString) {
if (((UnicodeString) data).getString().equals("ver")) {
UnicodeString version = (UnicodeString) given.get(data);
result.ver = version.getString();
} else if (((UnicodeString) data).getString().equals("response")) {
result.response = ((ByteString) (given.get(data))).getBytes();
}
}
}
if (result.response == null || result.ver == null)
throw new ResponseException("Invalid JWT Cbor");
return result;
}
示例3: testEncode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
/**
* Test method for
* {@link com.google.webauthn.gaedemo.objects.AndroidSafetyNetAttestationStatement#encode()} and
* {@link com.google.webauthn.gaedemo.objects.AndroidSafetyNetAttestationStatement#decode(co.nstant.in.cbor.model.DataItem)}.
*/
@Test
public void testEncode() {
SecureRandom random = new SecureRandom();
AndroidSafetyNetAttestationStatement attStmt = new AndroidSafetyNetAttestationStatement();
attStmt.ver = "10";
attStmt.response = new byte[20];
random.nextBytes(attStmt.response);
try {
DataItem encoded = attStmt.encode();
AndroidSafetyNetAttestationStatement decoded =
AndroidSafetyNetAttestationStatement.decode(encoded);
assertEquals(decoded, attStmt);
} catch (CborException | ResponseException e) {
fail(e.getMessage());
}
}
示例4: decode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
/**
* @param attStmt
* @return Decoded FidoU2fAttestationStatement
*/
public static PackedAttestationStatement decode(DataItem attStmt) {
PackedAttestationStatement result = new PackedAttestationStatement();
Map given = null;
if (attStmt instanceof ByteString) {
byte[] temp = ((ByteString) attStmt).getBytes();
List<DataItem> dataItems = null;
try {
dataItems = CborDecoder.decode(temp);
} catch (Exception e) {
}
given = (Map) dataItems.get(0);
} else {
given = (Map) attStmt;
}
for (DataItem data : given.getKeys()) {
if (data instanceof UnicodeString) {
if (((UnicodeString) data).getString().equals("x5c")) {
Array array = (Array) given.get(data);
List<DataItem> list = array.getDataItems();
if (list.size() > 0) {
result.attestnCert = ((ByteString) list.get(0)).getBytes();
}
result.caCert = new ArrayList<byte[]>();
for (int i = 1; i < list.size(); i++) {
result.caCert.add(((ByteString) list.get(i)).getBytes());
}
} else if (((UnicodeString) data).getString().equals("sig")) {
result.sig = ((ByteString) (given.get(data))).getBytes();
} else if (((UnicodeString) data).getString().equals("alg")) {
result.alg = Algorithm.decode(((UnicodeString) (given.get(data))).getString());
} else if (((UnicodeString) data).getString().equals("ecdaaKeyId")) {
result.ecdaaKeyId = ((ByteString) (given.get(data))).getBytes();
}
}
}
return result;
}
示例5: encode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
@Override
public byte[] encode() throws CborException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
List<DataItem> dataItems =
new CborBuilder().addMap().put(new UnsignedInteger(KTY_LABEL), new UnsignedInteger(kty))
.put(new UnsignedInteger(ALG_LABEL), new NegativeInteger(alg.encodeToInt()))
.put(new NegativeInteger(N_LABEL), new ByteString(n))
.put(new NegativeInteger(E_LABEL), new ByteString(e)).end().build();
new CborEncoder(output).encode(dataItems);
return output.toByteArray();
}
示例6: encode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
@Override
public byte[] encode() throws CborException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
List<DataItem> dataItems =
new CborBuilder().addMap().put(new UnsignedInteger(KTY_LABEL), new UnsignedInteger(kty))
.put(new UnsignedInteger(ALG_LABEL), new NegativeInteger(alg.encodeToInt()))
.put(new NegativeInteger(CRV_LABEL), new UnsignedInteger(crv))
.put(new NegativeInteger(X_LABEL), new ByteString(x))
.put(new NegativeInteger(Y_LABEL), new ByteString(y)).end().build();
new CborEncoder(output).encode(dataItems);
return output.toByteArray();
}
示例7: decode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
/**
* @param attestationObject
* @return AttestationObject created from the provided byte array
* @throws CborException
* @throws ResponseException
*/
public static AttestationObject decode(byte[] attestationObject)
throws CborException, ResponseException {
AttestationObject result = new AttestationObject();
List<DataItem> dataItems = CborDecoder.decode(attestationObject);
if (dataItems.size() == 1 && dataItems.get(0) instanceof Map) {
DataItem attStmt = null;
Map attObjMap = (Map) dataItems.get(0);
for (DataItem key : attObjMap.getKeys()) {
if (key instanceof UnicodeString) {
if (((UnicodeString) key).getString().equals("fmt")) {
UnicodeString value = (UnicodeString) attObjMap.get(key);
result.fmt = value.getString();
}
if (((UnicodeString) key).getString().equals("authData")) {
byte[] authData = ((ByteString) attObjMap.get(key)).getBytes();
result.authData = AuthenticatorData.decode(authData);
}
if (((UnicodeString) key).getString().equals("attStmt")) {
attStmt = attObjMap.get(key);
}
}
}
if (attStmt != null) {
result.attStmt = AttestationStatement.decode(result.fmt, attStmt);
}
}
return result;
}
示例8: encode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
/**
* @return Encoded byte array containing AttestationObject data
* @throws CborException
*/
public byte[] encode() throws CborException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
List<DataItem> cbor =
new CborBuilder().addMap().put("fmt", fmt).put("authData", authData.encode())
.put(new UnicodeString("attStmt"), attStmt.encode()).end().build();
new CborEncoder(output).encode(cbor);
return output.toByteArray();
}
示例9: encode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
@Override
DataItem encode() throws CborException {
Map map = new Map();
map.put(new UnicodeString("ver"), new UnicodeString(ver));
map.put(new UnicodeString("response"), new ByteString(response));
return map;
}
示例10: decode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
/**
* @param attStmt
* @return Decoded FidoU2fAttestationStatement
*/
public static FidoU2fAttestationStatement decode(DataItem attStmt) {
FidoU2fAttestationStatement result = new FidoU2fAttestationStatement();
Map given = null;
if (attStmt instanceof ByteString) {
byte[] temp = ((ByteString) attStmt).getBytes();
List<DataItem> dataItems = null;
try {
dataItems = CborDecoder.decode(temp);
} catch (Exception e) {
}
given = (Map) dataItems.get(0);
} else {
given = (Map) attStmt;
}
for (DataItem data : given.getKeys()) {
if (data instanceof UnicodeString) {
if (((UnicodeString) data).getString().equals("x5c")) {
Array array = (Array) given.get(data);
List<DataItem> list = array.getDataItems();
if (list.size() > 0) {
result.attestnCert = ((ByteString) list.get(0)).getBytes();
}
result.caCert = new ArrayList<byte[]>();
for (int i = 1; i < list.size(); i++) {
result.caCert.add(((ByteString) list.get(i)).getBytes());
}
} else if (((UnicodeString) data).getString().equals("sig")) {
result.sig = ((ByteString) (given.get(data))).getBytes();
}
}
}
return result;
}
示例11: encode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
@Override
DataItem encode() throws CborException {
Map result = new Map();
Array x5c = new Array();
x5c.add(new ByteString(attestnCert));
for (byte[] cert : this.caCert) {
x5c.add(new ByteString(cert));
}
result.put(new UnicodeString("x5c"), x5c);
result.put(new UnicodeString("sig"), new ByteString(sig));
return result;
}
示例12: getHashMap
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
public static HashMap getHashMap(DataItem dataItem) {
HashMap hMap = new HashMap();
co.nstant.in.cbor.model.Map map = (co.nstant.in.cbor.model.Map)dataItem;
HashMap hashMap = new HashMap();
Iterator<DataItem> itr = map.getKeys().iterator();
while(itr.hasNext()) {
DataItem key = itr.next();
//System.out.println(map.get(key).getMajorType().toString());
if(map.get(key).getMajorType().toString().equals("MAP")) {
hMap.put(key.toString(), getHashMap(map.get(key)));
} else if(map.get(key).getMajorType().toString().equals("ARRAY")) {
Array cborArr = (Array)map.get(key);
ArrayList<String> arr = new ArrayList<String>();
for(int i = 0; i < cborArr.getDataItems().size(); i++) {
arr.add( cborArr.getDataItems().get(i).toString() );
}
hMap.put(key.toString(), arr);
} else {
String value = map.get(key).toString();
if(map.get(key).getMajorType().name().contains("INTEGER")) {
hMap.put(key.toString(),Integer.parseInt(value) );
} else if(map.get(key).getMajorType().name().contains("SPECIAL")){
SimpleValue simpleValue = (SimpleValue)map.get(key);
String temp = simpleValue.getSimpleValueType().toString().toLowerCase();
if(temp.equals("true") || temp.equals("false")) {
hMap.put(key.toString(), Boolean.getBoolean(temp));
} else {
hMap.put(key.toString(), temp);
}
}else {
hMap.put(key.toString(), value);
}
}
}
return hMap;
}
示例13: getCborHashMap
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
private static HashMap getCborHashMap(DataItem dataItem) {
HashMap hMap = new HashMap();
co.nstant.in.cbor.model.Map map = (co.nstant.in.cbor.model.Map)dataItem;
HashMap hashMap = new HashMap();
Iterator<DataItem> itr = map.getKeys().iterator();
while(itr.hasNext()) {
DataItem key = itr.next();
if(map.get(key).getMajorType().toString().equals("MAP")) {
hMap.put(key.toString(), getCborHashMap(map.get(key)));
} else if(map.get(key).getMajorType().toString().equals("ARRAY")) {
Array cborArr = (Array)map.get(key);
ArrayList<String> arr = new ArrayList<String>();
for(int i = 0; i < cborArr.getDataItems().size(); i++) {
arr.add( cborArr.getDataItems().get(i).toString() );
}
hMap.put(key.toString(), arr);
} else if(map.get(key).getMajorType().name().contains("SPECIAL")){
SimpleValue simpleValue = (SimpleValue)map.get(key);
String temp = simpleValue.getSimpleValueType().toString().toLowerCase();
if(temp.equals("true") || temp.equals("false")) {
hMap.put(key.toString(), Boolean.getBoolean(temp));
} else {
hMap.put(key.toString(), temp);
}
} else {
String value = map.get(key).toString();
if(map.get(key).getMajorType().name().contains("INTEGER")) {
hMap.put(key.toString(),Integer.parseInt(value) );
} else {
hMap.put(key.toString(), value);
}
}
}
return hMap;
}
示例14: encodeCBOR
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
public static byte[] encodeCBOR(String json) {
byte[] result = {};
try {
ObjectMapper mapper = new ObjectMapper();
HashMap<String, Object> map = mapper.readValue(json, new TypeReference<Map<String, Object>>(){});
DataItem dataItem = getDataItem(map);
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
CborEncoder encoder = new CborEncoder(byteOutputStream);
encoder.encode(dataItem);
byte[] cborBytes = byteOutputStream.toByteArray();
StringBuffer sb = new StringBuffer();
//String cborEncodedStr = new BigInteger(cborBytes).toString(16);
for(int i = 0; i < cborBytes.length; i++) {
sb.append(Integer.toHexString(0x0100 + (cborBytes[i] & 0x00FF)).substring(1));
}
result = sb.toString().getBytes();
}catch(Exception ex) {
return null;
}
return result;
}
示例15: encode
import co.nstant.in.cbor.model.DataItem; //导入依赖的package包/类
/**
* @return Encoded AttestationStatement
* @throws CborException
*/
abstract DataItem encode() throws CborException;