本文整理汇总了C#中net.named_data.jndn.Name.size方法的典型用法代码示例。如果您正苦于以下问题:C# Name.size方法的具体用法?C# Name.size怎么用?C# Name.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.named_data.jndn.Name
的用法示例。
在下文中一共展示了Name.size方法的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: 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));
}
示例3: matchesName
/// <summary>
/// Check if this Interest's name matches the given name (using Name.match)
/// and the given name also conforms to the interest selectors.
/// </summary>
///
/// <param name="name">The name to check.</param>
/// <returns>True if the name and interest selectors match, otherwise false.</returns>
public bool matchesName(Name name)
{
if (!getName().match(name))
return false;
if (minSuffixComponents_ >= 0 &&
// Add 1 for the implicit digest.
!(name.size() + 1 - getName().size() >= minSuffixComponents_))
return false;
if (maxSuffixComponents_ >= 0 &&
// Add 1 for the implicit digest.
!(name.size() + 1 - getName().size() <= maxSuffixComponents_))
return false;
if (getExclude().size() > 0 && name.size() > getName().size()
&& getExclude().matches(name.get(getName().size())))
return false;
return true;
}
示例4: 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);
}
}
示例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 void setDefaultKeyNameForIdentity(Name keyName,
Name identityNameCheck)
{
Name identityName = keyName.getPrefix(-1);
if (identityNameCheck.size() > 0
&& !identityNameCheck.equals(identityName))
throw new SecurityException(
"The specified identity name does not match the key name");
String identity = identityName.toUri();
if (identityStore_.Contains(identity)) {
((MemoryIdentityStorage.IdentityRecord ) ILOG.J2CsMapping.Collections.Collections.Get(identityStore_,identity))
.setDefaultKey(new Name(keyName));
}
}
示例6: buildKeyChain
/// <summary>
/// Create a KeyChain with the a default name and key pair.
/// </summary>
///
/// <param name="certificateName">Set certificateName[0] to the signing certificateName.</param>
/// <returns>The KeyChain.</returns>
/// <exception cref="System.Security.SecurityException"></exception>
public static KeyChain buildKeyChain(Name[] certificateName)
{
MemoryIdentityStorage identityStorage = new MemoryIdentityStorage();
MemoryPrivateKeyStorage privateKeyStorage = new MemoryPrivateKeyStorage();
KeyChain keyChain = new KeyChain(new IdentityManager(identityStorage,
privateKeyStorage),
new SelfVerifyPolicyManager(identityStorage));
// initialize the storage with
Name keyName = new Name("/testname/DSK-123");
certificateName[0] = keyName.getSubName(0, keyName.size() - 1)
.append("KEY").append(keyName.get(-1)).append("ID-CERT")
.append("0");
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);
return keyChain;
}
示例7: doesMatch
/// <summary>
/// Check if the given name matches this filter. Match if name starts with this
/// filter's prefix. If this filter has the optional regexFilter then the
/// remaining components match the regexFilter regular expression.
/// For example, the following InterestFilter:
/// InterestFilter("/hello", "<world><>+")
/// will match all Interests, whose name has the prefix `/hello` which is
/// followed by a component `world` and has at least one more component after it.
/// Examples:
/// /hello/world/!
/// /hello/world/x/y/z
/// Note that the regular expression will need to match all remaining components
/// (e.g., there are implicit heading `^` and trailing `$` symbols in the
/// regular expression).
/// </summary>
///
/// <param name="name">The name to check against this filter.</param>
/// <returns>True if name matches this filter, otherwise false.</returns>
public bool doesMatch(Name name)
{
if (name.size() < prefix_.size())
return false;
if (hasRegexFilter()) {
// Perform a prefix match and regular expression match for the remaining
// components.
if (!prefix_.match(name))
return false;
return null != net.named_data.jndn.util.NdnRegexMatcher.match(regexFilterPattern_,
name.getSubName(prefix_.size()));
} else
// Just perform a prefix match.
return prefix_.match(name);
}
示例8: testUriConstructor
public void testUriConstructor()
{
Name name = new Name(expectedURI);
Assert.AssertEquals("Constructed name has " + name.size()
+ " components instead of 3", 3, name.size());
Assert.AssertEquals("URI is incorrect", expectedURI, name.toUri());
}
示例9: 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);
}
示例10: checkSetDefaultKeyNameForIdentity
/// <summary>
/// Throw an exception if it is an error for setDefaultKeyNameForIdentity to
/// set it.
/// </summary>
///
/// <param name="keyName">The key name.</param>
/// <param name="identityNameCheck">The identity name to check the keyName.</param>
/// <exception cref="System.Security.SecurityException">if the identity name does not match the key nameor other problem.</exception>
protected internal void checkSetDefaultKeyNameForIdentity(Name keyName,
Name identityNameCheck)
{
Name identityName = keyName.getPrefix(-1);
if (identityNameCheck.size() > 0
&& !identityNameCheck.equals(identityName))
throw new SecurityException(
"The specified identity name does not match the key name");
}
示例11: getKeyNameFromCertificatePrefix
private static Name getKeyNameFromCertificatePrefix(Name certificatePrefix)
{
Name result = new Name();
String keyString = "KEY";
int i = 0;
for (; i < certificatePrefix.size(); i++) {
if (certificatePrefix.get(i).toEscapedString().equals(keyString))
break;
}
if (i >= certificatePrefix.size())
throw new SecurityException(
"Identity Certificate Prefix does not have a KEY component");
result.append(certificatePrefix.getSubName(0, i));
result.append(certificatePrefix.getSubName(i + 1,
certificatePrefix.size() - i - 1));
return result;
}
示例12: nfdRegisterPrefix
/// <summary>
/// Do the work of registerPrefix to register with NFD.
/// </summary>
///
/// <param name="registeredPrefixId">registeredPrefixTable_ (assuming it has already been done).</param>
/// <param name="prefix"></param>
/// <param name="onInterest"></param>
/// <param name="onRegisterFailed"></param>
/// <param name="onRegisterSuccess"></param>
/// <param name="flags"></param>
/// <param name="commandKeyChain"></param>
/// <param name="commandCertificateName"></param>
/// <param name="wireFormat_0"></param>
/// <param name="face_1"></param>
/// <exception cref="System.Security.SecurityException">If cannot find the private key for thecertificateName.</exception>
private void nfdRegisterPrefix(long registeredPrefixId, Name prefix,
OnInterestCallback onInterest, OnRegisterFailed onRegisterFailed,
OnRegisterSuccess onRegisterSuccess, ForwardingFlags flags,
KeyChain commandKeyChain, Name commandCertificateName,
WireFormat wireFormat_0, Face face_1)
{
if (commandKeyChain == null)
throw new Exception(
"registerPrefix: The command KeyChain has not been set. You must call setCommandSigningInfo.");
if (commandCertificateName.size() == 0)
throw new Exception(
"registerPrefix: The command certificate name has not been set. You must call setCommandSigningInfo.");
ControlParameters controlParameters = new ControlParameters();
controlParameters.setName(prefix);
controlParameters.setForwardingFlags(flags);
Interest commandInterest = new Interest();
// Determine whether to use remote prefix registration.
bool faceIsLocal;
try {
faceIsLocal = isLocal();
} catch (IOException ex) {
logger_.log(
ILOG.J2CsMapping.Util.Logging.Level.INFO,
"Register prefix failed: Error attempting to determine if the face is local: {0}",
ex);
try {
onRegisterFailed.onRegisterFailed(prefix);
} catch (Exception exception) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed",
exception);
}
return;
}
if (faceIsLocal) {
commandInterest.setName(new Name("/localhost/nfd/rib/register"));
// The interest is answered by the local host, so set a short timeout.
commandInterest.setInterestLifetimeMilliseconds(2000.0d);
} else {
commandInterest.setName(new Name("/localhop/nfd/rib/register"));
// The host is remote, so set a longer timeout.
commandInterest.setInterestLifetimeMilliseconds(4000.0d);
}
// NFD only accepts TlvWireFormat packets.
commandInterest.getName().append(
controlParameters.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get()));
makeCommandInterest(commandInterest, commandKeyChain,
commandCertificateName, net.named_data.jndn.encoding.TlvWireFormat.get());
// Send the registration interest.
Node.RegisterResponse response = new Node.RegisterResponse (
new RegisterResponse.Info(prefix, onRegisterFailed,
onRegisterSuccess, registeredPrefixId, onInterest, face_1),
this);
try {
expressInterest(getNextEntryId(), commandInterest, response,
response, null, wireFormat_0, face_1);
} catch (IOException ex_2) {
// Can't send the interest. Call onRegisterFailed.
logger_.log(
ILOG.J2CsMapping.Util.Logging.Level.INFO,
"Register prefix failed: Error sending the register prefix interest to the forwarder: {0}",
ex_2);
try {
onRegisterFailed.onRegisterFailed(prefix);
} catch (Exception exception_3) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed",
exception_3);
}
}
}
示例13: encodeName
/// <summary>
/// Encode the name as NDN-TLV to the encoder.
/// </summary>
///
/// <param name="name">The name to encode.</param>
/// <param name="signedPortionBeginOffset">name component and ends just before the final name component (which is assumed to be a signature for a signed interest).</param>
/// <param name="signedPortionEndOffset">name component and ends just before the final name component (which is assumed to be a signature for a signed interest).</param>
/// <param name="encoder">The TlvEncoder to receive the encoding.</param>
private static void encodeName(Name name, int[] signedPortionBeginOffset,
int[] signedPortionEndOffset, TlvEncoder encoder)
{
int saveLength = encoder.getLength();
// Encode the components backwards.
int signedPortionEndOffsetFromBack = 0;
for (int i = name.size() - 1; i >= 0; --i) {
encodeNameComponent(name.get(i), encoder);
if (i == name.size() - 1)
signedPortionEndOffsetFromBack = encoder.getLength();
}
int signedPortionBeginOffsetFromBack = encoder.getLength();
encoder.writeTypeAndLength(net.named_data.jndn.encoding.tlv.Tlv.Name, encoder.getLength() - saveLength);
signedPortionBeginOffset[0] = encoder.getLength()
- signedPortionBeginOffsetFromBack;
if (name.size() == 0)
// There is no "final component", so set signedPortionEndOffset
// arbitrarily.
signedPortionEndOffset[0] = signedPortionBeginOffset[0];
else
signedPortionEndOffset[0] = encoder.getLength()
- signedPortionEndOffsetFromBack;
}
示例14: matchesRelation
/// <summary>
/// Determines if a name satisfies the relation to another name, based on
/// matchRelation.
/// </summary>
///
/// <param name="name"></param>
/// <param name="matchName"></param>
/// <param name="matchRelation">name as a prefix "is-strict-prefix-of" - passes if the name has the other name as a prefix, and is not equal "equal" - passes if the two names are equal</param>
/// <returns>True if matches.</returns>
private static bool matchesRelation(Name name, Name matchName,
String matchRelation)
{
bool passed = false;
if (matchRelation.equals("is-strict-prefix-of")) {
if (matchName.size() == name.size())
passed = false;
else if (matchName.match(name))
passed = true;
} else if (matchRelation.equals("is-prefix-of")) {
if (matchName.match(name))
passed = true;
} else if (matchRelation.equals("equal")) {
if (matchName.equals(name))
passed = true;
}
return passed;
}
示例15: certNameFromKeyName
private static Name certNameFromKeyName(Name keyName, int keyIdx)
{
if (keyIdx < 0)
keyIdx = keyName.size() + keyIdx;
return keyName.getPrefix(keyIdx).append("KEY")
.append(keyName.getSubName(keyIdx)).append("ID-CERT")
.append("0");
}