예제 #1
0
    def fingerprint_contents(self):
        """Produce the contents of the condition hash.

        This function is called internally by the ``condition``
        method/property.

        Returns:
            bytes: Encoded contents of fingerprint hash.

        """
        if not self.subcondition:
            raise MissingDataError('Requires subcondition')

        try:
            subcondition_asn1_dict = self.subcondition.condition.to_asn1_dict()
        except AttributeError:
            subcondition_asn1_dict = self.subcondition.to_asn1_dict()

        return der_encode(
            nat_decode(
                {
                    'prefix': self.prefix,
                    'maxMessageLength': self.max_message_length,
                    'subcondition': subcondition_asn1_dict,
                },
                asn1Spec=PrefixFingerprintContents()))
예제 #2
0
    def fingerprint_contents(self):
        """Produce the contents of the condition hash.

        This function is called internally by the `getCondition` method.

        Returns:
            bytes: Encoded contents of fingerprint hash.

        """
        if self.modulus is None:
            raise MissingDataError('Requires modulus')

        asn1_obj = nat_decode({'modulus': self.modulus},
                              asn1Spec=RsaFingerprintContents())
        asn1_der = der_encode(asn1_obj)
        return asn1_der
예제 #3
0
    def fingerprint_contents(self):
        """Produce the contents of the condition hash.

        This function is called internally by the `getCondition` method.

        Returns:
            bytes: Encoded contents of fingerprint hash.

        """
        if self.modulus is None:
            raise MissingDataError('Requires modulus')

        asn1_obj = nat_decode({'modulus': self.modulus},
                              asn1Spec=RsaFingerprintContents())
        asn1_der = der_encode(asn1_obj)
        return asn1_der
예제 #4
0
    def fingerprint_contents(self):
        """

        .. todo:: docs

        """
        subconditions = [
            c.to_asn1_dict() for c in sorted(
                map(lambda c: c['body']
                    if isinstance(c['body'], Condition)
                    else c['body'].condition, self.subconditions))
        ]
        asn1_fingerprint_obj = nat_decode(
            {'threshold': self.threshold, 'subconditions': subconditions},
            asn1Spec=ThresholdFingerprintContents(),
        )
        return der_encode(asn1_fingerprint_obj)
    def serialize_binary(self):
        """
        Serialize fulfillment to bytes.

        Encodes the fulfillment as a string of bytes. This is used
        internally for encoding subfulfillments, but can also be used to
        passing around fulfillments in a binary protocol for instance.

        Returns:
            bytes: Serialized fulfillment (DER encoded).
        """
        asn1_dict = {self.TYPE_ASN1: self.asn1_dict_payload}
        asn1 = nat_decode(asn1_dict, asn1Spec=Asn1Fulfillment())
        try:
            bin_obj = der_encode(asn1)
        except PyAsn1Error as exc:
            raise ASN1EncodeError('Failed to encode fulfillment.') from exc
        return bin_obj
예제 #6
0
    def fingerprint_contents(self):
        """

        .. todo:: docs

        """
        subconditions = [
            c.to_asn1_dict() for c in sorted(
                map(
                    lambda c: c['body'] if isinstance(c['body'], Condition)
                    else c['body'].condition, self.subconditions))
        ]
        asn1_fingerprint_obj = nat_decode(
            {
                'threshold': self.threshold,
                'subconditions': subconditions
            },
            asn1Spec=ThresholdFingerprintContents(),
        )
        return der_encode(asn1_fingerprint_obj)
예제 #7
0
    def serialize_binary(self):
        """
        Serialize condition to a buffer.

        Encodes the condition as a string of bytes. This is used internally for
        encoding subconditions, but can also be used to passing around conditions
        in a binary protocol for instance.

        CONDITION =
            VARUINT TYPE_BITMASK
            VARBYTES HASH
            VARUINT MAX_COST

        Return:
            Serialized condition
        """
        asn1_dict = self.to_asn1_dict()
        asn1_condition = nat_decode(asn1_dict, asn1Spec=Asn1Condition())
        binary_condition = der_encode(asn1_condition)
        return binary_condition
예제 #8
0
    def fingerprint_contents(self):
        """Produce the contents of the condition hash.

        This function is called internally by the ``condition``
        method/property.

        Returns:
            bytes: Encoded contents of fingerprint hash.

        """
        if not self.subcondition:
            raise MissingDataError('Requires subcondition')

        try:
            subcondition_asn1_dict = self.subcondition.condition.to_asn1_dict()
        except AttributeError:
            subcondition_asn1_dict = self.subcondition.to_asn1_dict()

        return der_encode(nat_decode({
            'prefix': self.prefix,
            'maxMessageLength': self.max_message_length,
            'subcondition': subcondition_asn1_dict,
        }, asn1Spec=PrefixFingerprintContents()))
예제 #9
0
    def serialize_binary(self):
        """
        Serialize fulfillment to bytes.

        Encodes the fulfillment as a string of bytes. This is used
        internally for encoding subfulfillments, but can also be used to
        passing around fulfillments in a binary protocol for instance.

        Returns:
            bytes: Serialized fulfillment (DER encoded).
        """
        asn1_dict = {self.TYPE_ASN1: self.asn1_dict_payload}
        try:
            asn1 = nat_decode(asn1_dict, asn1Spec=Asn1Fulfillment())
        except TypeError as exc:
            raise ASN1DecodeError(
                'Internal error! Failed to transform dict "{}" '
                'into pyasn1 schema object.'.format(asn1_dict)
            ) from exc
        try:
            bin_obj = der_encode(asn1)
        except PyAsn1Error as exc:
            raise ASN1EncodeError('Failed to encode fulfillment.') from exc
        return bin_obj
예제 #10
0
 def fingerprint_contents(self):
     asn1_fingerprint_obj = nat_decode(
         {'publicKey': self.public_key},
         asn1Spec=Ed25519FingerprintContents(),
     )
     return der_encode(asn1_fingerprint_obj)
예제 #11
0
 def fingerprint_contents(self):
     asn1_fingerprint_obj = nat_decode(
         {'publicKey': self.public_key},
         asn1Spec=Ed25519FingerprintContents(),
     )
     return der_encode(asn1_fingerprint_obj)
예제 #12
0
 def fingerprint_contents(self):
     asn1_fingerprint_obj = nat_decode(
         {'script': self.script},
         asn1Spec=ZenroomFingerprintContents(),
     )
     return der_encode(asn1_fingerprint_obj)