本文整理汇总了Java中co.nstant.in.cbor.CborDecoder.decode方法的典型用法代码示例。如果您正苦于以下问题:Java CborDecoder.decode方法的具体用法?Java CborDecoder.decode怎么用?Java CborDecoder.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类co.nstant.in.cbor.CborDecoder
的用法示例。
在下文中一共展示了CborDecoder.decode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import co.nstant.in.cbor.CborDecoder; //导入方法依赖的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;
}
示例2: decode
import co.nstant.in.cbor.CborDecoder; //导入方法依赖的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;
}
示例3: decode
import co.nstant.in.cbor.CborDecoder; //导入方法依赖的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;
}
示例4: decodeCBOR
import co.nstant.in.cbor.CborDecoder; //导入方法依赖的package包/类
public static String decodeCBOR(byte[] cbor) {
String result = "";
try {
StringBuilder sb = new StringBuilder(cbor.length);
for(byte b : cbor) {
sb.append((char) b);
}
String hexText = sb.toString();
byte[] bytes = new BigInteger(hexText, 16).toByteArray();
InputStream inputStream = new ByteArrayInputStream(bytes);
CborDecoder decoder = new CborDecoder(inputStream);
List<DataItem> dataItems = decoder.decode();
// added and test, then blocked in 2017-12-08 to test with NTELS, it should be deleted after that.
//DataItem dt = dataItems.get(0);
//System.out.println("######### dt===>" + dt.toString());
//return dt.toString();
HashMap hashMap = new HashMap();
hashMap = getCborHashMap(dataItems.get(1));
JSONObject jsonObject = new JSONObject();
jsonObject.put("__message__", hashMap);
jsonObject = (JSONObject)jsonObject.get("__message__");
result = jsonObject.toString();
}catch(CborException ex) {
return null;
}
return result;
}