# Path: macaroonbakery/bakery/_codec.py
# _PUBLIC_KEY_PREFIX_LEN = 4
# _KEY_LEN = 32
# _VERSION3_CAVEAT_MIN_LEN = 1 + 4 + 32 + 24 + 16 + 1
# def encode_caveat(condition, root_key, third_party_info, key, ns):
# def _encode_caveat_v1(condition, root_key, third_party_pub_key, key):
# def _encode_caveat_v2_v3(version, condition, root_key, third_party_pub_key,
#                          key, ns):
# def _encode_secret_part_v2_v3(version, condition, root_key, ns):
# def decode_caveat(key, caveat):
# def _decode_caveat_v1(key, caveat):
# def _decode_caveat_v2_v3(version, key, caveat):
# def _decode_secret_part_v2_v3(version, data):
# def encode_uvarint(n, data):
# def decode_uvarint(data):


import base64
import macaroonbakery.bakery as bakery
import macaroonbakery.checkers as checkers
import nacl.public
import six
from unittest import TestCase
from macaroonbakery.bakery import _codec as codec
            nacl.public.PrivateKey(base64.b64decode(
                'KXpsoJ9ujZYi/O2Cca6kaWh65MSawzy79LWkrjOfzcs=')))
        root_key = base64.b64decode('vDxEmWZEkgiNEFlJ+8ruXe3qDSLf1H+o')
        # This caveat has been generated from the go code
        # to check the compatibilty

        encrypted_cav = six.b(
            'eyJUaGlyZFBhcnR5UHVibGljS2V5IjoiOFA3R1ZZc3BlWlN4c'
            '3hFdmJsSVFFSTFqdTBTSWl0WlIrRFdhWE40cmxocz0iLCJGaX'
            'JzdFBhcnR5UHVibGljS2V5IjoiSDlqSFJqSUxidXppa1VKd2o'
            '5VGtDWk9qeW5oVmtTdHVsaUFRT2d6Y0NoZz0iLCJOb25jZSI6'
            'Ii9lWTRTTWR6TGFxbDlsRFc3bHUyZTZuSzJnVG9veVl0IiwiS'
            'WQiOiJra0ZuOGJEaEt4RUxtUjd0NkJxTU0vdHhMMFVqaEZjR1'
            'BORldUUExGdjVla1dWUjA4Uk1sbGJhc3c4VGdFbkhzM0laeVo'
            '0V2lEOHhRUWdjU3ljOHY4eUt4dEhxejVEczJOYmh1ZDJhUFdt'
            'UTVMcVlNWitmZ2FNaTAxdE9DIn0=')
        cav = bakery.decode_caveat(tp_key, encrypted_cav)
        self.assertEquals(cav, bakery.ThirdPartyCaveatInfo(
            condition='caveat condition',
            first_party_public_key=fp_key.public_key,
            third_party_key_pair=tp_key,
            root_key=root_key,
            caveat=encrypted_cav,
            version=bakery.VERSION_1,
            id=None,
            namespace=bakery.legacy_namespace()
        ))

    def test_decode_caveat_v2_from_go(self):
        tp_key = bakery.PrivateKey(nacl.public.PrivateKey(

# Path: macaroonbakery/bakery/_codec.py
# _PUBLIC_KEY_PREFIX_LEN = 4
# _KEY_LEN = 32
# _VERSION3_CAVEAT_MIN_LEN = 1 + 4 + 32 + 24 + 16 + 1
# def encode_caveat(condition, root_key, third_party_info, key, ns):
# def _encode_caveat_v1(condition, root_key, third_party_pub_key, key):
# def _encode_caveat_v2_v3(version, condition, root_key, third_party_pub_key,
#                          key, ns):
# def _encode_secret_part_v2_v3(version, condition, root_key, ns):
# def decode_caveat(key, caveat):
# def _decode_caveat_v1(key, caveat):
# def _decode_caveat_v2_v3(version, key, caveat):
# def _decode_secret_part_v2_v3(version, data):
# def encode_uvarint(n, data):
# def decode_uvarint(data):


# Path: macaroonbakery/tests/test_codec.py
import base64
import macaroonbakery.bakery as bakery
import macaroonbakery.checkers as checkers
import nacl.public
import six
from unittest import TestCase
from macaroonbakery.bakery import _codec as codec

            nacl.public.PrivateKey(base64.b64decode(
                'KXpsoJ9ujZYi/O2Cca6kaWh65MSawzy79LWkrjOfzcs=')))
        root_key = base64.b64decode('vDxEmWZEkgiNEFlJ+8ruXe3qDSLf1H+o')
        # This caveat has been generated from the go code
        # to check the compatibilty

        encrypted_cav = six.b(
            'eyJUaGlyZFBhcnR5UHVibGljS2V5IjoiOFA3R1ZZc3BlWlN4c'
            '3hFdmJsSVFFSTFqdTBTSWl0WlIrRFdhWE40cmxocz0iLCJGaX'
            'JzdFBhcnR5UHVibGljS2V5IjoiSDlqSFJqSUxidXppa1VKd2o'
            '5VGtDWk9qeW5oVmtTdHVsaUFRT2d6Y0NoZz0iLCJOb25jZSI6'
            'Ii9lWTRTTWR6TGFxbDlsRFc3bHUyZTZuSzJnVG9veVl0IiwiS'
            'WQiOiJra0ZuOGJEaEt4RUxtUjd0NkJxTU0vdHhMMFVqaEZjR1'
            'BORldUUExGdjVla1dWUjA4Uk1sbGJhc3c4VGdFbkhzM0laeVo'
            '0V2lEOHhRUWdjU3ljOHY4eUt4dEhxejVEczJOYmh1ZDJhUFdt'
            'UTVMcVlNWitmZ2FNaTAxdE9DIn0=')
        cav = bakery.decode_caveat(tp_key, encrypted_cav)
        self.assertEquals(cav, bakery.ThirdPartyCaveatInfo(
            condition='caveat condition',
            first_party_public_key=fp_key.public_key,
            third_party_key_pair=tp_key,
            root_key=root_key,
            caveat=encrypted_cav,
            version=bakery.VERSION_1,
            id=None,
            namespace=bakery.legacy_namespace()
        ))

    def test_decode_caveat_v2_from_go(self):
        tp_key = bakery.PrivateKey(nacl.public.PrivateKey(

            base64.b64decode(