当前位置: 首页>>代码示例>>Java>>正文


Java CborDecoder类代码示例

本文整理汇总了Java中co.nstant.in.cbor.CborDecoder的典型用法代码示例。如果您正苦于以下问题:Java CborDecoder类的具体用法?Java CborDecoder怎么用?Java CborDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CborDecoder类属于co.nstant.in.cbor包,在下文中一共展示了CborDecoder类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:google,项目名称:webauthndemo,代码行数:40,代码来源:FidoU2fAttestationStatement.java

示例2: 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;
}
 
开发者ID:google,项目名称:webauthndemo,代码行数:44,代码来源:PackedAttestationStatement.java

示例3: 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;
}
 
开发者ID:google,项目名称:webauthndemo,代码行数:38,代码来源:AttestationObject.java

示例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;
	
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:42,代码来源:Utils.java


注:本文中的co.nstant.in.cbor.CborDecoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。