blob: d61247f78f9418f3e2e3a32aad14ac5a05c9eeb7 [file] [log] [blame]
Mate Toth-Pal51b61982022-03-17 14:19:30 +01001#!/usr/bin/env python3
2#-------------------------------------------------------------------------------
3# Copyright (c) 2019-2022, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7#-------------------------------------------------------------------------------
8
9import argparse
10import sys
11
12import yaml
13from iatverifier.util import convert_token_to_map
14from iatverifier.psa_iot_profile1_token_verifier import PSAIoTProfile1TokenVerifier
15
16
17if __name__ == '__main__':
Mate Toth-Pal6978f7c2022-03-30 14:38:55 +020018
19 token_verifiers = {
20 "PSA-IoT-Profile1-token": PSAIoTProfile1TokenVerifier,
21 }
22
Mate Toth-Pal51b61982022-03-17 14:19:30 +010023 parser = argparse.ArgumentParser()
24 parser.add_argument('source', help='A compiled COSE IAT token.')
25 parser.add_argument('-o', '--outfile',
26 help='''Output file for the depompiled claims. If this is not
27 specified, the claims will be written to standard output.''')
Mate Toth-Pal6978f7c2022-03-30 14:38:55 +020028 parser.add_argument('-t', '--token-type',
29 help='''The type of the Token.''',
30 choices=token_verifiers.keys(),
31 required=True)
Mate Toth-Pal51b61982022-03-17 14:19:30 +010032 args = parser.parse_args()
33
Mate Toth-Pal6978f7c2022-03-30 14:38:55 +020034 verifier = token_verifiers[args.token_type].get_verifier()
Mate Toth-Pal51b61982022-03-17 14:19:30 +010035 with open(args.source, 'rb') as fh:
36 token_map = convert_token_to_map(fh.read(), verifier)
37
38 if args.outfile:
39 with open(args.outfile, 'w') as wfh:
40 yaml.dump(token_map, wfh)
41 else:
42 yaml.dump(token_map, sys.stdout)
43
44