new Consumer(face, keyChain, groupName, consumerName, database, cKeyLink, dKeyLink)
A Consumer manages fetched group keys used to decrypt a data packet in the
group-based encryption protocol.
Create a Consumer to use the given ConsumerDb, Face and other values.
Parameters:
Name | Type | Description |
---|---|---|
face |
Face | The face used for data packet and key fetching. |
keyChain |
KeyChain | The keyChain used to verify data packets. |
groupName |
Name | The reading group name that the consumer belongs to. This makes a copy of the Name. |
consumerName |
Name | The identity of the consumer. This makes a copy of the Name. |
database |
ConsumerDb | The ConsumerDb database for storing decryption keys. |
cKeyLink |
Link | (optional) The Link object to use in Interests for C-KEY retrieval. This makes a copy of the Link object. If the Link object's getDelegations().size() is zero, don't use it. If omitted, don't use a Link object. |
dKeyLink |
Link | (optional) The Link object to use in Interests for D-KEY retrieval. This makes a copy of the Link object. If the Link object's getDelegations().size() is zero, don't use it. If omitted, don't use a Link object. |
- Source:
Methods
(static) decrypt_(encryptedContent, keyBits, onPlainText, onError)
Decrypt encryptedContent using keyBits.
Parameters:
Name | Type | Description |
---|---|---|
encryptedContent |
Blob | EncryptedContent | The EncryptedContent to decrypt, or a Blob which is first decoded as an EncryptedContent. |
keyBits |
Blob | The key value. |
onPlainText |
function | When the data packet is decrypted, this calls onPlainText(decryptedBlob) with the decrypted Blob. |
onError |
function | This calls onError(errorCode, message) for an error, where errorCode is an error code from EncryptError.ErrorCode. |
- Source:
(static) decryptPromise_(encryptedContent, keyBits) → {Promise|SyncPromise}
Decrypt encryptedContent using keyBits.
Parameters:
Name | Type | Description |
---|---|---|
encryptedContent |
Blob | EncryptedContent | The EncryptedContent to decrypt, or a Blob which is first decoded as an EncryptedContent. |
keyBits |
Blob | The key value. |
- Source:
Returns:
A promise that returns the decrypted Blob, or
that is rejected with Consumer.Error or other error.
- Type
- Promise | SyncPromise
(static) Error(errorCode, message)
Consume.Error is used internally from promised-based methods to reject with
an error object that has the errorCode and message returned through the
onError callback.
Parameters:
Name | Type | Description |
---|---|---|
errorCode |
number | An error code from EncryptError.ErrorCode. |
message |
string | The error message. |
- Source:
addDecryptionKey(keyName, keyBlob, onComplete, onError)
Add a new decryption key with keyName and keyBlob to the database.
Parameters:
Name | Type | Description |
---|---|---|
keyName |
Name | The key name. |
keyBlob |
Blob | The encoded key. |
onComplete |
function | (optional) This calls onComplete() when the key is added. (Some database libraries only use a callback, so onComplete is required to use these.) |
onError |
function | (optional) If defined, then onComplete must be defined and if there is an exception, then this calls onError(exception) where exception is Error if the consumer name is not a prefix of the key name, or ConsumerDb.Error if a key with the same keyName already exists, or other database error. If onComplete is defined but onError is undefined, then this will log any thrown exception. (Some database libraries only use a callback, so onError is required to be notified of an exception.) |
- Source:
addDecryptionKeyPromise(keyName, keyBlob, useSync) → {Promise|SyncPromise}
Add a new decryption key with keyName and keyBlob to the database.
Parameters:
Name | Type | Description |
---|---|---|
keyName |
Name | The key name. |
keyBlob |
Blob | The encoded key. |
useSync |
boolean | (optional) If true then return a SyncPromise which is already fulfilled. If omitted or false, this may return a SyncPromise or an async Promise. |
- Source:
Returns:
A promise that fulfills when the key is added,
or that is rejected with Error if the consumer name is not a prefix of the
key name, or ConsumerDb.Error if a key with the same keyName already exists,
or other database error.
- Type
- Promise | SyncPromise
consume(contentName, onConsumeComplete, onError, link)
Express an Interest to fetch the content packet with contentName, and
decrypt it, fetching keys as needed.
Parameters:
Name | Type | Description |
---|---|---|
contentName |
Name | The name of the content packet. |
onConsumeComplete |
function | When the content packet is fetched and decrypted, this calls onConsumeComplete(contentData, result) where 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. |
onError |
function | This calls onError(errorCode, message) for an error, where errorCode is an error code from EncryptError.ErrorCode. 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. |
link |
Link | (optional) The Link object to use in Interests for data retrieval. This makes a copy of the Link object. If the Link object's getDelegations().size() is zero, don't use it. If omitted, don't use a Link object. |
- Source:
decryptCKey_(cKeyData, onPlainText, onError)
Decrypt cKeyData.
Parameters:
Name | Type | Description |
---|---|---|
cKeyData |
Data | The C-KEY data packet. |
onPlainText |
function | When the data packet is decrypted, this calls onPlainText(decryptedBlob) with the decrypted Blob. |
onError |
function | This calls onError(errorCode, message) for an error, where errorCode is an error code from EncryptError.ErrorCode. |
- Source:
decryptContent_(data, onPlainText, onError)
Decrypt the data packet.
Parameters:
Name | Type | Description |
---|---|---|
data |
Data | The data packet. This does not verify the packet. |
onPlainText |
function | When the data packet is decrypted, this calls onPlainText(decryptedBlob) with the decrypted Blob. |
onError |
function | This calls onError(errorCode, message) for an error, where errorCode is an error code from EncryptError.ErrorCode. |
- Source:
decryptDKeyPromise_(dKeyData) → {Promise|SyncPromise}
Decrypt dKeyData.
Parameters:
Name | Type | Description |
---|---|---|
dKeyData |
Data | The D-KEY data packet. |
- Source:
Returns:
A promise that returns the decrypted Blob, or
that is rejected with Consumer.Error or other error.
- Type
- Promise | SyncPromise
getDecryptionKeyPromise_(decryptionKeyName) → {Promise|SyncPromise}
Get the encoded blob of the decryption key with decryptionKeyName from the
database.
Parameters:
Name | Type | Description |
---|---|---|
decryptionKeyName |
Name | The key name. |
- Source:
Returns:
A promise that returns a Blob with the encoded
key (or an isNull Blob if cannot find the key with decryptionKeyName), or
that is rejected with ConsumerDb.Error for a database error.
- Type
- Promise | SyncPromise
sendInterest_(interest, nRetrials, link, onVerified, onError)
Express the interest, call verifyData for the fetched Data packet and call
onVerified if verify succeeds. If verify fails, call
onError(EncryptError.ErrorCode.Validation, "verifyData failed"). If the
interest times out, re-express nRetrials times. If the interest times out
nRetrials times, or for a network Nack, call
onError(EncryptError.ErrorCode.DataRetrievalFailure, interest.getName().toUri()).
Parameters:
Name | Type | Description |
---|---|---|
interest |
Interest | The Interest to express. |
nRetrials |
number | The number of retrials left after a timeout. |
link |
Link | The Link object to use in the Interest. This does not make a copy of the Link object. If the Link object's getDelegations().size() is zero, don't use it. |
onVerified |
function | When the fetched Data packet validation succeeds, this calls onVerified(data). |
onError |
function | This calls onError(errorCode, message) for an error, where errorCode is an error code from EncryptError.ErrorCode. |
- Source:
setGroup(groupName)
Set the group name.
Parameters:
Name | Type | Description |
---|---|---|
groupName |
Name | The reading group name that the consumer belongs to. This makes a copy of the Name. |
- Source: