def testA03(self):
     "util.ordict: __delitem__ via index"
     d = ordict()
     d['a'] = 22
     d['b'] = 33
     del d[0]
     self.assertEqual(d.list(), [33])
Example #2
0
 def testA03(self):
     "util.ordict: __delitem__ via index"
     d = ordict()
     d['a'] = 22
     d['b'] = 33
     del d[0]
     self.assertEqual(d.list(), [33])
Example #3
0
    def __init__(self, pkts=None, *args, **kwords):
        """Initialize public key message.

        :Parameters:
            - `pkts`: *optional* list of packets to build message with

        :Exceptions:
            - `PGPKeyMsgError`: first block is not a primary key block
        """
        import openpgp.sap.util.ordict as ORD

        self._b_primary = None
        self._b_subkeys = ORD.ordict()
        self._b_userids = ORD.ordict()
        self._b_userattrs = []

        if isinstance(pkts, list):

            if pkts[0].tag.type in [PKT_PUBLICKEY, PKT_PRIVATEKEY]:

                # first block must be a public key or secret key
                block = Block(pkts[0].body.id, pkts, idx=0)
                self.new_primary(
                    block)  # no signatures are required for primary
                idx = len(block.seq())

                try:
                    while pkts[idx].tag.type not in [
                            PKT_PUBLICKEY, PKT_PRIVATEKEY
                    ]:
                        # indiscriminate order
                        block = Block(self.primary_id, pkts, idx=idx)

                        if not block.local_bindings:
                            break  # subblocks require a primary key binding

                        self.add_subblock(block)
                        idx += len(block.seq())

                except IndexError, BlockLeaderError:
                    pass
            else:
                raise PGPKeyMsgError(
                    "First block to key message must be primary or secret key."
                )
Example #4
0
    def __init__(self, pkts=None, *args, **kwords):
        """Initialize public key message.

        :Parameters:
            - `pkts`: *optional* list of packets to build message with

        :Exceptions:
            - `PGPKeyMsgError`: first block is not a primary key block
        """
        import openpgp.sap.util.ordict as ORD

        self._b_primary = None
        self._b_subkeys = ORD.ordict()
        self._b_userids = ORD.ordict()
        self._b_userattrs = []
       
        if isinstance(pkts, list):

            if pkts[0].tag.type in [PKT_PUBLICKEY, PKT_PRIVATEKEY]:

                # first block must be a public key or secret key
                block = Block(pkts[0].body.id, pkts, idx=0)
                self.new_primary(block) # no signatures are required for primary
                idx = len(block.seq())

                try:
                    while pkts[idx].tag.type not in [PKT_PUBLICKEY,
                                                     PKT_PRIVATEKEY]:
                        # indiscriminate order
                        block = Block(self.primary_id, pkts, idx=idx)

                        if not block.local_bindings:
                            break # subblocks require a primary key binding

                        self.add_subblock(block)
                        idx += len(block.seq())

                except IndexError, BlockLeaderError:
                    pass
            else:
                raise PGPKeyMsgError("First block to key message must be primary or secret key.")
 def testA02(self):
     "util.ordict: index access == keyword access"
     d = ordict()
     d['a'] = 22
     self.assertEqual(d['a'], d[0])
 def testA01(self):
     "util.ordict: __setitem__/__getitem__"
     d = ordict()
     d['a'] = 23
     self.assertEqual(23, d['a'])
Example #7
0
 def testA02(self):
     "util.ordict: index access == keyword access"
     d = ordict()
     d['a'] = 22
     self.assertEqual(d['a'], d[0])
Example #8
0
 def testA01(self):
     "util.ordict: __setitem__/__getitem__"
     d = ordict()
     d['a'] = 23
     self.assertEqual(23, d['a'])