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


C# Name.appendImplicitSha256Digest方法代码示例

本文整理汇总了C#中net.named_data.jndn.Name.appendImplicitSha256Digest方法的典型用法代码示例。如果您正苦于以下问题:C# Name.appendImplicitSha256Digest方法的具体用法?C# Name.appendImplicitSha256Digest怎么用?C# Name.appendImplicitSha256Digest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.named_data.jndn.Name的用法示例。


在下文中一共展示了Name.appendImplicitSha256Digest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: testImplicitSha256Digest

        public void testImplicitSha256Digest()
        {
            Name name = new Name();

            ByteBuffer digest = toBuffer(new int[] { 0x28, 0xba, 0xd4, 0xb5, 0x27,
                    0x5b, 0xd3, 0x92, 0xdb, 0xb6, 0x70, 0xc7, 0x5c, 0xf0, 0xb6,
                    0x6f, 0x13, 0xf7, 0x94, 0x2b, 0x21, 0xe8, 0x0f, 0x55, 0xc0,
                    0xe8, 0x6b, 0x37, 0x47, 0x53, 0xa5, 0x48, 0x00, 0x00 });

            digest.limit(32);
            name.appendImplicitSha256Digest(new Blob(digest, true));
            name.appendImplicitSha256Digest(new Blob(digest, true)
                    .getImmutableArray());
            Assert.AssertEquals(name.get(0), name.get(1));

            digest.limit(34);
            bool gotError = true;
            try {
                name.appendImplicitSha256Digest(new Blob(digest, true));
                gotError = false;
            } catch (Exception ex) {
            }
            if (!gotError)
                Assert.Fail("Expected error in appendImplicitSha256Digest");

            digest.limit(30);
            gotError = true;
            try {
                name.appendImplicitSha256Digest(new Blob(digest, true));
                gotError = false;
            } catch (Exception ex_0) {
            }
            if (!gotError)
                Assert.Fail("Expected error in appendImplicitSha256Digest");

            // Add name.get(2) as a generic component.
            digest.limit(32);
            name.append(new Blob(digest, true));
            Assert.AssertTrue(name.get(0).compare(name.get(2)) < 0);
            Assert.AssertTrue(name.get(0).getValue().equals(name.get(2).getValue()));

            // Add name.get(3) as a generic component whose first byte is greater.
            digest.position(1);
            digest.limit(33);
            name.append(new Blob(digest, true));
            Assert.AssertTrue(name.get(0).compare(name.get(3)) < 0);

            Assert.AssertEquals(
                    "sha256digest="
                            + "28bad4b5275bd392dbb670c75cf0b66f13f7942b21e80f55c0e86b374753a548",
                    name.get(0).toEscapedString());

            Assert.AssertEquals(true, name.get(0).isImplicitSha256Digest());
            Assert.AssertEquals(false, name.get(2).isImplicitSha256Digest());

            gotError = true;
            try {
                new Name("/hello/sha256digest=hmm");
                gotError = false;
            } catch (Exception ex_1) {
            }
            if (!gotError)
                Assert.Fail("Expected error in new Name from URI");

            // Check canonical URI encoding (lower case).
            Name name2 = new Name(
                    "/hello/sha256digest="
                            + "28bad4b5275bd392dbb670c75cf0b66f13f7942b21e80f55c0e86b374753a548");
            Assert.AssertEquals(name.get(0), name2.get(1));

            // Check that it will accept a hex value in upper case too.
            name2 = new Name(
                    "/hello/sha256digest="
                            + "28BAD4B5275BD392DBB670C75CF0B66F13F7942B21E80F55C0E86B374753A548");
            Assert.AssertEquals(name.get(0), name2.get(1));

            // This is not valid sha256digest component. It should be treated as generic.
            name2 = new Name(
                    "/hello/SHA256DIGEST="
                            + "28BAD4B5275BD392DBB670C75CF0B66F13F7942B21E80F55C0E86B374753A548");
            Assert.AssertFalse(name.get(0).equals(name2.get(1)));
            Assert.AssertTrue(name2.get(1).isGeneric());
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:83,代码来源:TestNameMethods.cs

示例2: getFullName

        /// <summary>
        /// Get the Data packet's full name, which includes the final
        /// ImplicitSha256Digest component based on the wire encoding for a particular
        /// wire format.
        /// </summary>
        ///
        /// <param name="wireFormat">A WireFormat object used to encode the Data packet.</param>
        /// <returns>The full name. You must not change the Name object - if you need
        /// to change it then make a copy.</returns>
        public Name getFullName(WireFormat wireFormat)
        {
            // The default full name depends on the default wire encoding.
            if (!getDefaultWireEncoding().isNull() && defaultFullName_.size() > 0
                    && getDefaultWireEncodingFormat() == wireFormat)
                // We already have a full name. A non-null default wire encoding means
                // that the Data packet fields have not changed.
                return defaultFullName_;

            Name fullName = new Name(getName());
            // wireEncode will use the cached encoding if possible.
            fullName.appendImplicitSha256Digest(net.named_data.jndn.util.Common.digestSha256(wireEncode(
                    wireFormat).buf()));

            if (wireFormat == net.named_data.jndn.encoding.WireFormat.getDefaultWireFormat())
                // wireEncode has already set defaultWireEncodingFormat_.
                defaultFullName_ = fullName;

            return fullName;
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:29,代码来源:Data.cs


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