本文整理汇总了C#中net.onError方法的典型用法代码示例。如果您正苦于以下问题:C# net.onError方法的具体用法?C# net.onError怎么用?C# net.onError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net
的用法示例。
在下文中一共展示了net.onError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: decrypt
/// <summary>
/// Decode encryptedBlob as an EncryptedContent and decrypt using keyBits.
/// </summary>
///
/// <param name="encryptedBlob">The encoded EncryptedContent to decrypt.</param>
/// <param name="keyBits">The key value.</param>
/// <param name="onPlainText_0"></param>
/// <param name="onError_1">This calls onError.onError(errorCode, message) for an error.</param>
private static void decrypt(Blob encryptedBlob, Blob keyBits,
Consumer.OnPlainText onPlainText_0, net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
{
EncryptedContent encryptedContent = new EncryptedContent();
try {
encryptedContent.wireDecode(encryptedBlob);
} catch (EncodingException ex) {
try {
onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.InvalidEncryptedFormat,
ex.Message);
} catch (Exception exception) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
}
return;
}
decrypt(encryptedContent, keyBits, onPlainText_0, onError_1);
}
示例2: encryptContentKey
/// <summary>
/// Get the content key from the database_ and encrypt it for the timeSlot
/// using encryptionKey.
/// </summary>
///
/// <param name="encryptionKey">The encryption key value.</param>
/// <param name="eKeyName">The key name for the EncryptedContent.</param>
/// <param name="timeSlot_0">The time slot as milliseconds since Jan 1, 1970 UTC.</param>
/// <param name="onEncryptedKeys_1">encrypted content key Data packets. If onEncryptedKeys is null, this does not use it.</param>
/// <returns>True if encryption succeeds, otherwise false.</returns>
private bool encryptContentKey(Blob encryptionKey, Name eKeyName,
double timeSlot_0, Producer.OnEncryptedKeys onEncryptedKeys_1, net.named_data.jndn.encrypt.EncryptError.OnError onError_2)
{
double timeCount = Math.Round(timeSlot_0,MidpointRounding.AwayFromZero);
Producer.KeyRequest keyRequest = (Producer.KeyRequest ) ILOG.J2CsMapping.Collections.Collections.Get(keyRequests_,timeCount);
Name keyName = new Name(namespace_);
keyName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_C_KEY);
keyName.append(net.named_data.jndn.encrypt.Schedule.toIsoString(getRoundedTimeSlot(timeSlot_0)));
Blob contentKey = database_.getContentKey(timeSlot_0);
Data cKeyData = new Data();
cKeyData.setName(keyName);
EncryptParams paras = new EncryptParams(net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.RsaOaep);
try {
net.named_data.jndn.encrypt.algo.Encryptor.encryptData(cKeyData, contentKey, eKeyName,
encryptionKey, paras);
} catch (Exception ex) {
try {
onError_2.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.EncryptionFailure, ex.Message);
} catch (Exception exception) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
}
return false;
}
keyChain_.sign(cKeyData);
ILOG.J2CsMapping.Collections.Collections.Add(keyRequest.encryptedKeys,cKeyData);
updateKeyRequest(keyRequest, timeCount, onEncryptedKeys_1);
return true;
}
示例3: decryptDKey
/// <summary>
/// Decrypt dKeyData.
/// </summary>
///
/// <param name="dKeyData">The D-KEY data packet.</param>
/// <param name="onPlainText_0"></param>
/// <param name="onError_1">This calls onError.onError(errorCode, message) for an error.</param>
internal void decryptDKey(Data dKeyData, Consumer.OnPlainText onPlainText_0,
net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
{
// Get the encrypted content.
Blob dataContent = dKeyData.getContent();
// Process the nonce.
// dataContent is a sequence of the two EncryptedContent.
EncryptedContent encryptedNonce = new EncryptedContent();
try {
encryptedNonce.wireDecode(dataContent);
} catch (EncodingException ex) {
try {
onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.InvalidEncryptedFormat,
ex.Message);
} catch (Exception exception) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
}
return;
}
Name consumerKeyName = encryptedNonce.getKeyLocator().getKeyName();
// Get consumer decryption key.
Blob consumerKeyBlob;
try {
consumerKeyBlob = getDecryptionKey(consumerKeyName);
} catch (ConsumerDb.Error ex_2) {
try {
onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.NoDecryptKey,
"Database error: " + ex_2.Message);
} catch (Exception exception_3) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception_3);
}
return;
}
if (consumerKeyBlob.size() == 0) {
try {
onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.NoDecryptKey,
"The desired consumer decryption key in not in the database");
} catch (Exception exception_4) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception_4);
}
return;
}
// Process the D-KEY.
// Use the size of encryptedNonce to find the start of encryptedPayload.
ByteBuffer encryptedPayloadBuffer = dataContent.buf().duplicate();
encryptedPayloadBuffer.position(encryptedNonce.wireEncode().size());
Blob encryptedPayloadBlob_5 = new Blob(encryptedPayloadBuffer,
false);
if (encryptedPayloadBlob_5.size() == 0) {
try {
onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.InvalidEncryptedFormat,
"The data packet does not satisfy the D-KEY packet format");
} catch (Exception ex_6) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", ex_6);
}
return;
}
// Decrypt the D-KEY.
Consumer.OnPlainText callerOnPlainText_7 = onPlainText_0;
decrypt(encryptedNonce, consumerKeyBlob, new Consumer.Anonymous_C0 (callerOnPlainText_7, encryptedPayloadBlob_5, onError_1), onError_1);
}
示例4: decryptContent
/// <summary>
/// Decrypt the data packet.
/// </summary>
///
/// <param name="data">The data packet. This does not verify the packet.</param>
/// <param name="onPlainText_0"></param>
/// <param name="onError_1">This calls onError.onError(errorCode, message) for an error.</param>
internal void decryptContent(Data data, Consumer.OnPlainText onPlainText_0,
net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
{
// Get the encrypted content.
EncryptedContent dataEncryptedContent_2 = new EncryptedContent();
try {
dataEncryptedContent_2.wireDecode(data.getContent());
} catch (EncodingException ex) {
try {
onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.InvalidEncryptedFormat,
ex.Message);
} catch (Exception exception) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
}
return;
}
Name cKeyName_3 = dataEncryptedContent_2.getKeyLocator().getKeyName();
// Check if the content key is already in the store.
Blob cKey = (Blob) ILOG.J2CsMapping.Collections.Collections.Get(cKeyMap_,cKeyName_3);
if (cKey != null)
decrypt(dataEncryptedContent_2, cKey, onPlainText_0, onError_1);
else {
// Retrieve the C-KEY Data from the network.
Name interestName = new Name(cKeyName_3);
interestName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_FOR)
.append(groupName_);
Interest interest_4 = new Interest(interestName);
// Prepare the callback functions.
OnData onData_5 = new Consumer.Anonymous_C4 (this, cKeyName_3, onError_1, onPlainText_0,
dataEncryptedContent_2);
OnTimeout onTimeout = new Consumer.Anonymous_C3 (this, onData_5, onError_1, interest_4);
// Express the Interest.
try {
face_.expressInterest(interest_4, onData_5, onTimeout);
} catch (IOException ex_6) {
try {
onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.IOException,
"expressInterest error: " + ex_6.Message);
} catch (Exception exception_7) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception_7);
}
}
}
}
示例5: decryptCKey
/// <summary>
/// Decrypt cKeyData.
/// </summary>
///
/// <param name="cKeyData">The C-KEY data packet.</param>
/// <param name="onPlainText_0"></param>
/// <param name="onError_1">This calls onError.onError(errorCode, message) for an error.</param>
internal void decryptCKey(Data cKeyData, Consumer.OnPlainText onPlainText_0,
net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
{
// Get the encrypted content.
Blob cKeyContent = cKeyData.getContent();
EncryptedContent cKeyEncryptedContent_2 = new EncryptedContent();
try {
cKeyEncryptedContent_2.wireDecode(cKeyContent);
} catch (EncodingException ex) {
try {
onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.InvalidEncryptedFormat,
ex.Message);
} catch (Exception exception) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
}
return;
}
Name eKeyName = cKeyEncryptedContent_2.getKeyLocator().getKeyName();
Name dKeyName_3 = eKeyName.getPrefix(-3);
dKeyName_3.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_D_KEY).append(
eKeyName.getSubName(-2));
// Check if the decryption key is already in the store.
Blob dKey = (Blob) ILOG.J2CsMapping.Collections.Collections.Get(dKeyMap_,dKeyName_3);
if (dKey != null)
decrypt(cKeyEncryptedContent_2, dKey, onPlainText_0, onError_1);
else {
// Get the D-Key Data.
Name interestName = new Name(dKeyName_3);
interestName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_FOR).append(
consumerName_);
Interest interest_4 = new Interest(interestName);
// Prepare the callback functions.
OnData onData_5 = new Consumer.Anonymous_C2 (this, onError_1, onPlainText_0, dKeyName_3,
cKeyEncryptedContent_2);
OnTimeout onTimeout = new Consumer.Anonymous_C1 (this, interest_4, onData_5, onError_1);
// Express the Interest.
try {
face_.expressInterest(interest_4, onData_5, onTimeout);
} catch (IOException ex_6) {
try {
onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.IOException,
"expressInterest error: " + ex_6.Message);
} catch (Exception exception_7) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception_7);
}
}
}
}
示例6: consume
/// <summary>
/// Express an Interest to fetch the content packet with contentName, and
/// decrypt it, fetching keys as needed.
/// </summary>
///
/// <param name="contentName">The name of the content packet.</param>
/// <param name="onConsumeComplete_0">contentData is the fetched Data packet and result is the decrypted plain text Blob. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
/// <param name="onError_1">better error handling the callback should catch and properly handle any exceptions.</param>
public void consume(Name contentName,
Consumer.OnConsumeComplete onConsumeComplete_0, net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
{
Interest interest_2 = new Interest(contentName);
// Prepare the callback functions.
OnData onData_3 = new Consumer.Anonymous_C6 (this, onConsumeComplete_0, onError_1);
OnTimeout onTimeout = new Consumer.Anonymous_C5 (this, interest_2, onData_3, onError_1);
// Express the Interest.
try {
face_.expressInterest(interest_2, onData_3, onTimeout);
} catch (IOException ex) {
try {
onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.IOException,
"expressInterest error: " + ex.Message);
} catch (Exception exception) {
logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
}
}
}