pyndn.security.pib.detail package

Submodules

pyndn.security.pib.detail.pib_identity_impl module

This module defines the PibIdentityImpl class which provides the backend implementation for PibIdentity. A PibIdentity has only one backend instance, but may have multiple frontend handles. Each frontend handle is associated with the only one backend PibIdentityImpl.

class pyndn.security.pib.detail.pib_identity_impl.PibIdentityImpl(identityName, pibImpl, needInit)[source]

Bases: object

Create a PibIdentityImpl with identityName.

Parameters:
  • identityName (Name) – The name of the identity, which is copied.
  • pibImpl (PibImpl) – The Pib backend implementation.
  • needInit (bool) – If true and the identity does not exist in the pibImpl back end, then create it (and If no default identity has been set, identityName becomes the default). If false, then throw Pib.Error if the identity does not exist in the pibImpl back end.
Raises:

Pib.Error – If the identity does not exist in the pibImpl back end and needInit is false.

addKey(key, keyName)[source]

Add the key. If a key with the same name already exists, overwrite the key. If no default key for the identity has been set, then set the added key as default for the identity.

Parameters:
  • key (an array which implements the buffer protocol) – The public key bits. This copies the buffer.
  • keyName (Name) – The name of the key. This copies the name.
Returns:

The PibKey object.

Return type:

PibKey

getDefaultKey()[source]

Get the default key of this Identity.

Returns:The default PibKey.
Return type:PibKey
Raises:Pib.Error – If the default key has not been set.
getKey(keyName)[source]

Get the key with name keyName.

Parameters:

keyName (Name) – The name of the key.

Returns:

The PibKey object.

Return type:

PibKey

Raises:
  • ValueError – If keyName does not match the identity name.
  • Pib.Error – If the key does not exist.
getName()[source]

Get the name of the identity.

Returns:The name of the identity. You must not change the Name object. If you need to change it then make a copy.
Return type:Name
removeKey(keyName)[source]

Remove the key with keyName and its related certificates. If the key does not exist, do nothing.

Parameters:keyName (Name) – The name of the key.
setDefaultKey(keyOrKeyName, arg2=None)[source]

setDefaultKey has two forms: setDefaultKey(keyName) - Set the key with name keyName as the default key of the identity. setDefaultKey(key, keyName) - Add a key with name keyName and set it as the default key of the identity.

Parameters:
  • key (an array which implements the buffer protocol) – The buffer of encoded key bytes. (This is only used when calling setDefaultKey(key, keyName). )
  • keyName (Name) – The name of the key. This copies the name.
Returns:

The PibKey object of the default key.

Return type:

PibKey

Raises:
  • ValueError – If the name of the key does not match the identity name.
  • Pib.Error – If calling setDefaultKey(keyName) and the key does not exist, or if calling setDefaultKey(key, keyName) and a key with the same name already exists.

pyndn.security.pib.detail.pib_key_impl module

This module defines the PibKeyImpl class which provides the backend implementation for PibKey. A PibKey has only one backend instance, but may have multiple frontend handles. Each frontend handle is associated with the only one backend PibKeyImpl.

class pyndn.security.pib.detail.pib_key_impl.PibKeyImpl(keyName, arg2, arg3=None)[source]

Bases: object

The constructor has two forms: PibKeyImpl(keyName, keyEncoding, pibImpl) - Create a PibKeyImpl with keyName. If the key does not exist in the backend implementation, add it by creating it from the keyEncoding. If a key with keyName already exists, overwrite it. PibKeyImpl(keyName, pibImpl) - Create a PibKeyImpl with keyName. Initialize the cached key encoding with pibImpl.getKeyBits().

Parameters:
  • keyName (Name) – The name of the key, which is copied.
  • keyEncoding (an array which implements the buffer protocol) – The buffer of encoded key bytes, which is copied. (This is only used in the constructor form PibKeyImpl(keyName, keyEncoding, pibImpl) .)
  • pibImpl (PibImpl) – The Pib backend implementation.
Raises:

Pib.Error – If the constructor is the form PibKeyImpl(keyName, pibImpl) (without the keyEncoding) and the key with keyName does not exist.

addCertificate(certificate)[source]

Add the certificate. If a certificate with the same name (without implicit digest) already exists, then overwrite the certificate. If no default certificate for the key has been set, then set the added certificate as default for the key.

Parameters:certificate (CertificateV2) – The certificate to add. This copies the object.
Raises:ValueError – If the name of the certificate does not match the key name.
getCertificate(certificateName)[source]

Get the certificate with name certificateName.

Parameters:

certificateName (Name) – The name of the certificate.

Returns:

A copy of the CertificateV2 object.

Return type:

CertificateV2

Raises:
  • ValueError – If certificateName does not match the key name.
  • Pib.Error – If the certificate does not exist.
getDefaultCertificate()[source]

Get the default certificate for this Key.

Returns:The default certificate.
Return type:CertificateV2
Raises:Pib.Error – the default certificate does not exist.
getIdentityName()[source]

Get the name of the identity this key belongs to.

Returns:The name of the identity. You must not change the object. If you need to change it, make a copy.
Return type:Name
getKeyType()[source]

Get the key type.

Returns:The key type.
Return type:an int from the KeyType enum
getName()[source]

Get the key name.

Returns:The key name. You must not change the object. If you need to change it, make a copy.
Return type:Name
getPublicKey()[source]

Get the public key encoding.

Returns:The public key encoding.
Return type:Blob
removeCertificate(certificateName)[source]

Remove the certificate with name certificateName. If the certificate does not exist, do nothing.

Parameters:certificateName (Name) – The name of the certificate.
Raises:ValueError – If certificateName does not match the key name.
setDefaultCertificate(certificateOrCertificateName)[source]

Set the existing certificate as the default certificate.

Parameters:

certificateOrCertificateName (Name or CertificateV2) – If certificateOrCertificateName is a Name, it is the name of the certificate, which must exist. Otherwise certificateOrCertificateName is the CertificateV2 to add (if necessary) and set as the default.

Returns:

The default certificate.

Return type:

CertificateV2

Raises:
  • ValueError – If the certificate name does not match the key name.
  • Pib.Error – If certificateOrCertificateName is the certificate Name and the certificate does not exist.

Module contents