Exemple #1
0
    def __repr__(self):
        _key = self._key_repr()

        if 'OKPKpD' in _key and len(_key['OKPKpD']) > 0:
            _key['OKPKpD'] = utils.truncate(_key['OKPKpD'])
        if 'OKPKpX' in _key and len(_key['OKPKpX']) > 0:
            _key['OKPKpX'] = utils.truncate(_key['OKPKpX'])
        if 'OKPKpY' in _key and len(_key['OKPKpY']) > 0:
            _key['OKPKpY'] = utils.truncate(_key['OKPKpY'])

        hdr = f'<COSE_Key(OKPKey): {_key}>'
        return hdr
Exemple #2
0
    def __repr__(self):
        _key = self._key_repr()

        if 'SymKpK' in _key and len(_key['SymKpK']) > 0:
            _key['SymKpK'] = utils.truncate(_key['SymKpK'])

        hdr = f'<COSE_Key(Symmetric): {_key}>'

        return hdr
Exemple #3
0
    def _hdr_repr(self) -> Tuple[dict, dict]:
        phdr = {(k.__name__ if hasattr(k, '__name__') else k): (
            self._phdr[k].__name__ if hasattr(self._phdr[k], '__name__') else self._phdr[k]) for k in self._phdr}

        uhdr = {(k.__name__ if hasattr(k, '__name__') else k): (
            self._uhdr[k].__name__ if hasattr(self._uhdr[k], '__name__') else self._uhdr[k]) for k in self._uhdr}

        if 'IV' in phdr and len(phdr['IV']) > 0:
            phdr['IV'] = utils.truncate(phdr['IV'])

        if 'IV' in uhdr and len(uhdr['IV']) > 0:
            uhdr['IV'] = utils.truncate(uhdr['IV'])

        if 'PARTIAL_IV' in phdr and len(phdr['PARTIAL_IV']) > 0:
            phdr['PARTIAL_IV'] = utils.truncate(phdr['PARTIAL_IV'])

        if 'PARTIAL_IV' in uhdr and len(uhdr['PARTIAL_IV']) > 0:
            uhdr['PARTIAL_IV'] = utils.truncate(uhdr['PARTIAL_IV'])

        return phdr, uhdr
    def _key_repr(self) -> dict:
        names = {
            kp.__name__ if hasattr(kp, '__name__') else kp:
            self.store[kp].__name__
            if hasattr(self.store[kp], '__name__') else self.store[kp]
            for kp in sorted(self.store,
                             key=lambda item: item.identifier
                             if hasattr(item, 'identifier') else 65536)
        }

        if KpKeyOps.__name__ in names:
            names[KpKeyOps.__name__] = [
                ops.__name__ if hasattr(ops, '__name__') else ops
                for ops in names[KpKeyOps.__name__]
            ]

        if 'BASE_IV' in names and len(names['BASE_IV']) > 0:
            names['BASE_IV'] = utils.truncate(names['BASE_IV'])

        return names