Beispiel #1
0
    def from_dict(cls, cose_key: dict) -> 'OKPKey':
        """
        Returns an initialized COSE Key object of type OKPKey.

        :param cose_key: Dictionary containing COSE Key parameters and there values.

        :return: an initialized OKPKey key
        """
        _optional_params = {}

        # extract and remove items from dict, if not found return default value
        x = CoseKey._extract_from_dict(cose_key, OKPKpX)
        d = CoseKey._extract_from_dict(cose_key, OKPKpD)
        curve = CoseKey._extract_from_dict(cose_key, OKPKpCurve, None)

        _optional_params.update(cose_key)
        CoseKey._remove_from_dict(_optional_params, OKPKpX)
        CoseKey._remove_from_dict(_optional_params, OKPKpD)
        CoseKey._remove_from_dict(_optional_params, OKPKpCurve)

        return cls(crv=curve,
                   x=x,
                   d=d,
                   optional_params=_optional_params,
                   allow_unknown_key_attrs=True)
Beispiel #2
0
    def from_dict(cls, cose_key: dict) -> 'SymmetricKey':
        """
        Returns an initialized COSE Key object of type SymmetricKey.

        :param cose_key: Dict containing COSE Key parameters and their values.

        :return: an initialized COSE SymmetricKey object
        """
        _optional_params = {}

        k = CoseKey._extract_from_dict(cose_key, SymKpK)

        _optional_params.update(cose_key)
        CoseKey._remove_from_dict(_optional_params, SymKpK)

        return cls(k=k,
                   optional_params=_optional_params,
                   allow_unknown_key_attrs=True)
Beispiel #3
0
    def from_dict(cls, cose_key: dict) -> 'RSAKey':
        """
        Returns an initialized COSE Key object of type RSAKey.

        :param cose_key: Dict containing COSE Key parameters and there values.
        :return: an initialized RSAKey key
        """
        _optional_params = {}

        e = CoseKey._extract_from_dict(cose_key, RSAKpE)
        n = CoseKey._extract_from_dict(cose_key, RSAKpN)
        d = CoseKey._extract_from_dict(cose_key, RSAKpD)
        p = CoseKey._extract_from_dict(cose_key, RSAKpP)
        q = CoseKey._extract_from_dict(cose_key, RSAKpQ)
        dp = CoseKey._extract_from_dict(cose_key, RSAKpDP)
        dq = CoseKey._extract_from_dict(cose_key, RSAKpDQ)
        qinv = CoseKey._extract_from_dict(cose_key, RSAKpQInv)
        other = CoseKey._extract_from_dict(cose_key, RSAKpOther, [])
        r_i = CoseKey._extract_from_dict(cose_key, RSAKpRi)
        d_i = CoseKey._extract_from_dict(cose_key, RSAKpDi)
        t_i = CoseKey._extract_from_dict(cose_key, RSAKpTi)

        _optional_params.update(cose_key)
        CoseKey._remove_from_dict(_optional_params, RSAKpE)
        CoseKey._remove_from_dict(_optional_params, RSAKpN)
        CoseKey._remove_from_dict(_optional_params, RSAKpD)
        CoseKey._remove_from_dict(_optional_params, RSAKpP)
        CoseKey._remove_from_dict(_optional_params, RSAKpQ)
        CoseKey._remove_from_dict(_optional_params, RSAKpDP)
        CoseKey._remove_from_dict(_optional_params, RSAKpDQ)
        CoseKey._remove_from_dict(_optional_params, RSAKpQInv)
        CoseKey._remove_from_dict(_optional_params, RSAKpOther)
        CoseKey._remove_from_dict(_optional_params, RSAKpQInv)
        CoseKey._remove_from_dict(_optional_params, RSAKpRi)
        CoseKey._remove_from_dict(_optional_params, RSAKpDi)
        CoseKey._remove_from_dict(_optional_params, RSAKpTi)

        return cls(e=e,
                   n=n,
                   d=d,
                   p=p,
                   q=q,
                   dp=dp,
                   dq=dq,
                   qinv=qinv,
                   other=other,
                   r_i=r_i,
                   d_i=d_i,
                   t_i=t_i,
                   optional_params=_optional_params,
                   allow_unknown_key_attrs=True)