revise cumbersome structure that is a opaque type
[platform/core/connectivity/nfc-manager-neard.git] / tools / ndef-tool / ndef-tool-sign.c
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include <stddef.h>
19 #include <stdint.h>
20 #include <stdbool.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24
25 #include "net_nfc.h"
26 #include "net_nfc_sign_record.h"
27 #include "ndef-tool.h"
28
29 bool ndef_tool_sign_message_from_file(const char *file_name, int begin_index, int end_index, char *cert_file, char *password)
30 {
31         bool result = false;
32         ndef_message_s *msg = NULL;
33         int32_t count = 0;
34
35         if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0)
36         {
37                 net_nfc_get_ndef_message_record_count(msg, &count);
38
39                 if (count > end_index)
40                 {
41                         fprintf(stdout, "count : %d\n", count);
42
43                         net_nfc_sign_records(msg, begin_index, end_index, cert_file, password);
44
45                         ndef_tool_write_ndef_message_to_file(file_name, msg);
46
47                         result = true;
48                 }
49
50                 net_nfc_free_ndef_message(msg);
51         }
52
53         return result;
54 }
55
56 bool ndef_tool_verify_message_from_file(const char *file_name)
57 {
58         bool result = false;
59         ndef_message_s *msg = NULL;
60
61         if (ndef_tool_read_ndef_message_from_file(file_name, &msg) > 0)
62         {
63                 result = (net_nfc_verify_signature_ndef_message(msg) == 0);
64
65                 net_nfc_free_ndef_message(msg);
66         }
67
68         return result;
69 }