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


Java PrefixSha256Fulfillment类代码示例

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


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

示例1: readFulfillment

import org.interledger.cryptoconditions.PrefixSha256Fulfillment; //导入依赖的package包/类
/**
 * Read a fulfillment from the underlying stream using OER encoding per the
 * specification:
 *
 * Fulfillment ::= SEQUENCE { type ConditionType, payload OCTET STRING }
 *
 * ConditionType ::= INTEGER { preimageSha256(0), rsaSha256(1),
 * prefixSha256(2), thresholdSha256(3), ed25519(4) } (0..65535)
 *
 * @return
 * @throws IOException
 * @throws OerDecodingException
 * @throws UnsupportedConditionException
 */
public Fulfillment readFulfillment()
        throws IOException, UnsupportedConditionException, OerDecodingException {
    final ConditionType type = readConditiontype();
    final FulfillmentPayload payload = new FulfillmentPayload(this.readPayload());

    ByteArrayInputStream byteStream = new ByteArrayInputStream(payload.payload);
    FulfillmentInputStream stream01 = new FulfillmentInputStream(byteStream);

    try {
        switch (type) {
            case PREIMAGE_SHA256:
                return new PreimageSha256Fulfillment(ConditionType.PREIMAGE_SHA256, payload);
            case PREFIX_SHA256:
                byte[] prefix = stream01.readOctetString();
                Fulfillment subfulfillment = stream01.readFulfillment();
                return new PrefixSha256Fulfillment(ConditionType.PREFIX_SHA256, payload, prefix, subfulfillment);
            case RSA_SHA256:
                /*
                 * REF: https://interledger.org/five-bells-condition/spec.html#rfc.section.4.4.2
                 * RsaSha256FulfillmentPayload ::= SEQUENCE {
                 * modulus OCTET STRING (SIZE(128..512)),
                 * signature OCTET STRING (SIZE(128..512))
                 * }
                 */
                byte[] bytesModulus = stream01.readOctetString();
                byte[] bytesSignatureRSASHA256 = stream01.readOctetString();
                BigInteger modulus = new BigInteger(1, bytesModulus); // TODO: RECHECK
                SignaturePayload signature01 = new SignaturePayload(bytesSignatureRSASHA256);
                return new RsaSha256Fulfillment(ConditionType.RSA_SHA256, payload, modulus, signature01);
            case ED25519:
                /*
             * REF: https://interledger.org/five-bells-condition/spec.html#rfc.section.4.5.2
             * Ed25519FulfillmentPayload ::= SEQUENCE {
             *     publicKey OCTET STRING (SIZE(32)),
             *     signature OCTET STRING (SIZE(64))
             * }
                 */
                byte[] bytesPublicKey = stream01.readOctetString();
                byte[] bytesSignatureEd25519 = stream01.readOctetString();
                java.security.PublicKey publicKey = Ed25519Fulfillment.publicKeyFromByteArray(new KeyPayload(bytesPublicKey));
                SignaturePayload signature02 = new SignaturePayload(bytesSignatureEd25519);
                return new Ed25519Fulfillment(ConditionType.ED25519, payload, publicKey, signature02);
            case THRESHOLD_SHA256:
                int threshold = stream01.readVarUInt();
                int conditionCount = stream01.readVarUInt();
                
                java.util.List<Integer>     weight_l = new java.util.ArrayList<Integer>();
                java.util.List<Fulfillment> ff_l     = new java.util.ArrayList<Fulfillment>();
                for (int idx=0; idx < conditionCount; idx++) {
                    int weight = stream01.readVarUInt();
                    weight_l.add(weight);
                    Fulfillment ff = stream01.readFulfillment();
                    ff_l.add(ff);
                }
                return new ThresholdSHA256Fulfillment(ConditionType.THRESHOLD_SHA256, payload, threshold, weight_l, ff_l);
            default:
                throw new RuntimeException("Unimplemented fulfillment type encountered.");
        }
    } catch (Exception e) {
        throw new RuntimeException(e.toString(), e);
    } finally {
        stream01.close();
    }

}
 
开发者ID:mgrand,项目名称:bigchaindb-java-driver,代码行数:80,代码来源:FulfillmentInputStream.java


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