本文整理汇总了C#中net.named_data.jndn.Name.get方法的典型用法代码示例。如果您正苦于以下问题:C# Name.get方法的具体用法?C# Name.get怎么用?C# Name.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.named_data.jndn.Name
的用法示例。
在下文中一共展示了Name.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testAppend
public void testAppend()
{
// could possibly split this into different tests
String uri = "/localhost/user/folders/files/%00%0F";
Name name = new Name(uri);
Name name2 = new Name("/localhost").append(new Name("/user/folders/"));
Assert.AssertEquals("Name constructed by appending names has " + name2.size()
+ " components instead of 3", 3, name2.size());
Assert.AssertTrue("Name constructed with append has wrong suffix", name2
.get(2).getValue().equals(new Blob("folders")));
name2 = name2.append("files");
Assert.AssertEquals("Name constructed by appending string has " + name2.size()
+ " components instead of 4", 4, name2.size());
name2 = name2.appendSegment(15);
Assert.AssertTrue(
"Name constructed by appending segment has wrong segment value",
name2.get(4).getValue()
.equals(new Blob(new int[] { 0x00, 0x0F })));
Assert.AssertTrue(
"Name constructed with append is not equal to URI constructed name",
name2.equals(name));
Assert.AssertEquals("Name constructed with append has wrong URI",
name.toUri(), name2.toUri());
}
示例2: testSegment
public void testSegment()
{
Name expected = new Name("/%00%27%10");
Assert.AssertTrue(expected.get(0).isSegment());
long number = 10000;
Assert.AssertEquals("appendSegment did not create the expected component",
expected, new Name().appendSegment(number));
try {
Assert.AssertEquals("toSegment did not return the expected value", number,
expected.get(0).toSegment());
} catch (EncodingException ex) {
Assert.Fail("Error while parsing a nonNegativeInteger: " + ex.Message);
}
}
示例3: testNumberWithMarker
public void testNumberWithMarker()
{
Name expected = new Name("/%AA%03%E8");
long number = 1000;
int marker = 0xAA;
Assert.AssertEquals(
"fromNumberWithMarker did not create the expected component",
expected, new Name().append(net.named_data.jndn.Name.Component
.fromNumberWithMarker(number, marker)));
try {
Assert.AssertEquals(
"toNumberWithMarker did not return the expected value",
number, expected.get(0).toNumberWithMarker(marker));
} catch (EncodingException ex) {
Assert.Fail("Error while parsing a nonNegativeInteger: " + ex.Message);
}
}
示例4: certificateNameToPublicKeyName
/// <summary>
/// Get the public key name from the full certificate name.
/// </summary>
///
/// <param name="certificateName">The full certificate name.</param>
/// <returns>The related public key name.</returns>
public static Name certificateNameToPublicKeyName(Name certificateName)
{
String idString = "ID-CERT";
bool foundIdString = false;
int idCertComponentIndex = certificateName.size() - 1;
for (; idCertComponentIndex + 1 > 0; --idCertComponentIndex) {
if (certificateName.get(idCertComponentIndex).toEscapedString()
.equals(idString)) {
foundIdString = true;
break;
}
}
if (!foundIdString)
throw new Exception("Incorrect identity certificate name "
+ certificateName.toUri());
Name tempName = certificateName.getSubName(0, idCertComponentIndex);
String keyString = "KEY";
bool foundKeyString = false;
int keyComponentIndex = 0;
for (; keyComponentIndex < tempName.size(); keyComponentIndex++) {
if (tempName.get(keyComponentIndex).toEscapedString()
.equals(keyString)) {
foundKeyString = true;
break;
}
}
if (!foundKeyString)
throw new Exception("Incorrect identity certificate name "
+ certificateName.toUri());
return tempName.getSubName(0, keyComponentIndex).append(
tempName.getSubName(keyComponentIndex + 1, tempName.size()
- keyComponentIndex - 1));
}
示例5: setDefaultKeyNameForIdentity
/// <summary>
/// Set a key as the default key of an identity. The identity name is inferred
/// from keyName.
/// </summary>
///
/// <param name="keyName">The name of the key.</param>
/// <param name="identityNameCheck"></param>
public override sealed void setDefaultKeyNameForIdentity(Name keyName,
Name identityNameCheck)
{
checkSetDefaultKeyNameForIdentity(keyName, identityNameCheck);
String keyId = keyName.get(-1).toEscapedString();
Name identityName = keyName.getPrefix(-1);
try {
// Reset the previous default Key.
PreparedStatement statement = database_
.prepareStatement("UPDATE Key SET default_key=0 WHERE "
+ net.named_data.jndn.security.identity.Sqlite3IdentityStorageBase.WHERE_setDefaultKeyNameForIdentity_reset);
statement.setString(1, identityName.toUri());
try {
statement.executeUpdate();
} finally {
statement.close();
}
// Set the current default Key.
statement = database_
.prepareStatement("UPDATE Key SET default_key=1 WHERE "
+ net.named_data.jndn.security.identity.Sqlite3IdentityStorageBase.WHERE_setDefaultKeyNameForIdentity_set);
statement.setString(1, identityName.toUri());
statement.setString(2, keyId);
try {
statement.executeUpdate();
} finally {
statement.close();
}
} catch (SQLException exception) {
throw new SecurityException("BasicIdentityStorage: SQLite error: "
+ exception);
}
}
示例6: match
/// <summary>
/// Check if the N components of this name are the same as the first N
/// components of the given name.
/// </summary>
///
/// <param name="name">The Name to check.</param>
/// <returns>true if this matches the given name, otherwise false. This always
/// returns true if this name is empty.</returns>
public bool match(Name name)
{
// This name is longer than the name we are checking it against.
if (components_.Count > name.components_.Count)
return false;
// Check if at least one of given components doesn't match. Check from last
// to first since the last components are more likely to differ.
for (int i = components_.Count - 1; i >= 0; --i) {
if (!get(i).getValue().equals(name.get(i).getValue()))
return false;
}
return true;
}
示例7: append
public Name append(Name name)
{
if (name == this)
// Copying from this name, so need to make a copy first.
return append(new Name(name));
for (int i = 0; i < name.components_.Count; ++i)
append(name.get(i));
return this;
}
示例8: CredentialStorage
public CredentialStorage()
{
this.identityStorage_ = new MemoryIdentityStorage();
this.privateKeyStorage_ = new MemoryPrivateKeyStorage();
this.keyChain_ = new KeyChain(new IdentityManager(
identityStorage_, privateKeyStorage_), new SelfVerifyPolicyManager(
identityStorage_));
Name keyName = new Name("/testname/DSK-123");
defaultCertName_ = keyName.getSubName(0, keyName.size() - 1)
.append("KEY").append(keyName.get(-1)).append("ID-CERT")
.append("0");
Name ecdsaKeyName = new Name("/testEcdsa/DSK-123");
ecdsaCertName_ = ecdsaKeyName.getSubName(0, ecdsaKeyName.size() - 1)
.append("KEY").append(ecdsaKeyName.get(-1)).append("ID-CERT")
.append("0");
try {
identityStorage_.addKey(keyName, net.named_data.jndn.security.KeyType.RSA, new Blob(
DEFAULT_RSA_PUBLIC_KEY_DER, false));
privateKeyStorage_.setKeyPairForKeyName(keyName, net.named_data.jndn.security.KeyType.RSA,
DEFAULT_RSA_PUBLIC_KEY_DER, DEFAULT_RSA_PRIVATE_KEY_DER);
#if false // Skip ECDSA for now.
identityStorage_.addKey(ecdsaKeyName, net.named_data.jndn.security.KeyType.ECDSA, new Blob(
DEFAULT_EC_PUBLIC_KEY_DER, false));
privateKeyStorage_.setKeyPairForKeyName(ecdsaKeyName,
net.named_data.jndn.security.KeyType.ECDSA, DEFAULT_EC_PUBLIC_KEY_DER,
DEFAULT_EC_PRIVATE_KEY_DER);
#endif
} catch (SecurityException ex) {
// Don't expect this to happen;
System.Console.Out.WriteLine("Exception setting test keys: " + ex);
identityStorage_ = null;
privateKeyStorage_ = null;
}
}
示例9: 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());
}
示例10: endsWithSegmentNumber
/// <summary>
/// Check if the last component in the name is a segment number.
/// </summary>
///
/// <param name="name">The name to check.</param>
/// <returns>True if the name ends with a segment number, otherwise false.</returns>
private static bool endsWithSegmentNumber(Name name)
{
return name.size() >= 1 && name.get(-1).isSegment();
}
示例11: testTimestamp
public void testTimestamp()
{
Name expected = new Name("/%FC%00%04%7BE%E3%1B%00%00");
Assert.AssertTrue(expected.get(0).isTimestamp());
// 40 years (not counting leap years) in microseconds.
long number = (long) 40 * 365 * 24 * 3600 * 1000000;
Assert.AssertEquals("appendTimestamp did not create the expected component",
expected, new Name().appendTimestamp(number));
try {
Assert.AssertEquals("toTimestamp did not return the expected value",
number, expected.get(0).toTimestamp());
} catch (EncodingException ex) {
Assert.Fail("Error while parsing a nonNegativeInteger: " + ex.Message);
}
}
示例12: Main
static void Main(string[] args)
{
var data = new Data();
data.wireDecode(new Blob(TlvData));
Console.Out.WriteLine("Decoded Data:");
dumpData(data);
// Set the content again to clear the cached encoding so we encode again.
data.setContent(data.getContent());
var encoding = data.wireEncode();
var reDecodedData = new Data();
reDecodedData.wireDecode(encoding);
Console.Out.WriteLine("");
Console.Out.WriteLine("Re-decoded Data:");
dumpData(reDecodedData);
var identityStorage = new MemoryIdentityStorage();
var privateKeyStorage = new MemoryPrivateKeyStorage();
var keyChain = new KeyChain
(new IdentityManager(identityStorage, privateKeyStorage),
new SelfVerifyPolicyManager(identityStorage));
// Initialize the storage.
var keyName = new Name("/testname/DSK-123");
var certificateName = keyName.getSubName(0, keyName.size() - 1).append
("KEY").append(keyName.get(-1)).append("ID-CERT").append("0");
identityStorage.addKey(keyName, KeyType.RSA, new Blob(DEFAULT_RSA_PUBLIC_KEY_DER));
privateKeyStorage.setKeyPairForKeyName
(keyName, KeyType.RSA, new ByteBuffer(DEFAULT_RSA_PUBLIC_KEY_DER),
new ByteBuffer(DEFAULT_RSA_PRIVATE_KEY_DER));
VerifyCallbacks callbacks = new VerifyCallbacks("Re-decoded Data");
keyChain.verifyData(reDecodedData, callbacks, callbacks);
var freshData = new Data(new Name("/ndn/abc"));
freshData.setContent(new Blob("SUCCESS!"));
freshData.getMetaInfo().setFreshnessPeriod(5000);
freshData.getMetaInfo().setFinalBlockId(new Name("/%00%09").get(0));
keyChain.sign(freshData, certificateName);
Console.Out.WriteLine("");
Console.Out.WriteLine("Freshly-signed Data:");
dumpData(freshData);
callbacks = new VerifyCallbacks("Freshly-signed Data");
keyChain.verifyData(freshData, callbacks, callbacks);
}
示例13: Main
static void Main(string[] args)
{
var face = new Face
(new TcpTransport(), new TcpTransport.ConnectionInfo("localhost"));
// For now, when setting face.setCommandSigningInfo, use a key chain with
// a default private key instead of the system default key chain. This
// is OK for now because NFD is configured to skip verification, so it
// ignores the system default key chain.
var identityStorage = new MemoryIdentityStorage();
var privateKeyStorage = new MemoryPrivateKeyStorage();
var keyChain = new KeyChain
(new IdentityManager(identityStorage, privateKeyStorage),
new SelfVerifyPolicyManager(identityStorage));
keyChain.setFace(face);
// Initialize the storage.
var keyName = new Name("/testname/DSK-123");
var certificateName = keyName.getSubName(0, keyName.size() - 1).append
("KEY").append(keyName.get(-1)).append("ID-CERT").append("0");
identityStorage.addKey(keyName, KeyType.RSA, new Blob(DEFAULT_RSA_PUBLIC_KEY_DER));
privateKeyStorage.setKeyPairForKeyName
(keyName, KeyType.RSA, new ByteBuffer(DEFAULT_RSA_PUBLIC_KEY_DER),
new ByteBuffer(DEFAULT_RSA_PRIVATE_KEY_DER));
face.setCommandSigningInfo(keyChain, certificateName);
var echo = new Echo(keyChain, certificateName);
var prefix = new Name("/testecho");
Console.Out.WriteLine("Register prefix " + prefix.toUri());
face.registerPrefix(prefix, echo, echo);
// The main event loop.
// Wait to receive one interest for the prefix.
while (echo.responseCount_ < 1) {
face.processEvents();
// We need to sleep for a few milliseconds so we don't use 100% of
// the CPU.
System.Threading.Thread.Sleep(5);
}
}
示例14: updateKeyStatus
/// <summary>
/// In table Key, set 'active' to isActive for the keyName.
/// </summary>
///
/// <param name="keyName">The name of the key.</param>
/// <param name="isActive">The value for the 'active' field.</param>
protected internal override void updateKeyStatus(Name keyName, bool isActive)
{
String keyId = keyName.get(-1).toEscapedString();
Name identityName = keyName.getPrefix(-1);
try {
PreparedStatement statement = database_
.prepareStatement("UPDATE Key SET active=? WHERE "
+ net.named_data.jndn.security.identity.Sqlite3IdentityStorageBase.WHERE_updateKeyStatus);
statement.setInt(1, ((isActive) ? 1 : 0));
statement.setString(2, identityName.toUri());
statement.setString(3, keyId);
try {
statement.executeUpdate();
} finally {
statement.close();
}
} catch (SQLException exception) {
throw new SecurityException("BasicIdentityStorage: SQLite error: "
+ exception);
}
}
示例15: setUp
public void setUp()
{
MemoryIdentityStorage identityStorage = new MemoryIdentityStorage();
MemoryPrivateKeyStorage privateKeyStorage = new MemoryPrivateKeyStorage();
keyChain = new KeyChain(new IdentityManager(identityStorage,
privateKeyStorage),
new SelfVerifyPolicyManager(identityStorage));
// Initialize the storage.
Name keyName = new Name("/testname/DSK-123");
certificateName = keyName.getSubName(0, keyName.size() - 1)
.append("KEY").append(keyName.get(-1)).append("ID-CERT")
.append("0");
try {
identityStorage.addKey(keyName, net.named_data.jndn.security.KeyType.RSA, new Blob(
DEFAULT_RSA_PUBLIC_KEY_DER, false));
privateKeyStorage.setKeyPairForKeyName(keyName, net.named_data.jndn.security.KeyType.RSA,
DEFAULT_RSA_PUBLIC_KEY_DER, DEFAULT_RSA_PRIVATE_KEY_DER);
} catch (SecurityException ex) {
// We don't expect this to happen.
ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(TestLink).FullName).log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null,
ex);
}
}