Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
dbt_readsmpkey.cpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2021 Gothel Software e.K.
4 * Copyright (c) 2021 ZAFENA AB
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26#include <cstring>
27#include <string>
28#include <memory>
29#include <cstdint>
30
32
33using namespace direct_bt;
34
35
36/** \file
37 * Reads and dumps an SMPKeyBin file.
38 *
39 * ### Invocation Examples:
40 * Using `scripts/run-dbt_readsmpkey.sh` from `dist` directory:
41 * * Read given SMPKeyBin file
42 * ~~~
43 * ../scripts/run-dbt_readsmpkey.sh keys/bd_001A7DDA7103_001A7DDA71081.key
44 * ~~~
45 */
46
47#include <cstdio>
48
49int main(int argc, char *argv[])
50{
51 int res = 0;
52 bool verbose=false;
53
54 for(int i=1; i<argc; i++) {
55 if( !strcmp("-verbose", argv[i]) || !strcmp("-v", argv[i]) ) {
56 verbose = true;
57 } else {
58 const std::string fname(argv[i]);
59 if( verbose ) {
60 fprintf(stderr, "Read: '%s'\n", fname.c_str());
61 }
62 SMPKeyBin key = SMPKeyBin::read(fname, verbose);
63 fprintf(stderr, "%s\n", key.toString().c_str());
64 if( !key.isValid() ) {
65 --res;
66 }
67 }
68 }
69 return res;
70}
Storage for SMP keys including required connection parameter per local adapter and remote device.
Definition: SMPKeyBin.hpp:79
std::string toString() const noexcept
Definition: SMPKeyBin.cpp:148
constexpr bool isValid() const noexcept
Returns true if.
Definition: SMPKeyBin.hpp:364
int main(int argc, char *argv[])