blob: 427db091c93329a6c5a9434091214c0c5e53a14f [file] [log] [blame]
Alexander Afanasyev5ba90362013-07-15 19:58:38 -07001## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2#
3# Copyright (c) 2011-2013, Regents of the University of California
4# Alexander Afanasyev
5#
6# GNU 3.0 license, See the LICENSE file for more information
7#
8# Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
9#
10
11#
12# Based on PyCCN code, copyrighted and licensed as follows
13#
14# Copyright (c) 2011-2013, Regents of the University of California
15# BSD license, See the COPYING file for more information
16# Written by: Derek Kulinski <takeda@takeda.tk>
17# Jeff Burke <jburke@ucla.edu>
18#
19
20from . import _ndn, Name
21
22def new_state():
23 return _ndn.nc_new_state()
24
25def generate_application_key(fixture_key, app_name):
26 app_id = _ndn.nc_app_id(app_name)
27 app_key = _ndn.nc_app_key(fixture_key, app_id)
28 return app_key
29
30def authenticate_command(state, name, app_name, app_key):
31 signed_name = _ndn.nc_authenticate_command(state, name.ccn_data, app_name, app_key)
32 return Name(ccn_data = signed_name)
33
34def authenticate_command_sig(state, name, app_name, key):
35 signed_name = _ndn.nc_authenticate_command_sig(state, name.ccn_data, app_name, key.ccn_data_private)
36 return Name(ccn_data = signed_name)
37
38def verify_command(state, name, max_time, **args):
39 if args.has_key('pub_key'): # TODO: use magic bytes to detect signature type, instead of asking caller to explicitly specify key type
40 args['pub_key'] = args['pub_key'].ccn_data_public
41 return _ndn.nc_verify_command(state, name.ccn_data, max_time, **args)