File: key.cc

package info (click to toggle)
yapet 0.6-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 6,012 kB
  • ctags: 2,913
  • sloc: ansic: 13,661; cpp: 11,384; sh: 4,814; makefile: 847; yacc: 291; sed: 16
file content (115 lines) | stat: -rw-r--r-- 1,795 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// $Id: key.cc 2845 2009-09-01 09:33:31Z rafi $

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
#ifdef HAVE_IOSTREAM
# include <iostream>
#endif
#ifdef HAVE_EXCEPTION
#include <exception>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <typeinfo>

#include <key.h>

const uint8_t expected_key[] = {
    0x3e,
    0xc3,
    0x34,
    0x5d,
    0x72,
    0x83,
    0xbd,
    0x09,
    0x60,
    0xa3,
    0x4f,
    0x6b,
    0x59,
    0x5b,
    0x93,
    0xb6,
    0x66,
    0x91,
    0x15,
    0x2c,
    0x65,
    0xc8,
    0x1a,
    0xdc,
    0x0a,
    0xc9,
    0x90,
    0xa7,
    0x93,
    0x70,
    0x96,
    0x94,
    0xa1,
    0x6d,
    0x81,
    0x06,
    0xc1,
    0x9a,
    0xba,
    0xd0,
    0x0e,
    0x94,
    0xd0,
    0xd1,
    0xf3,
    0xeb,
    0x5d,
    0x4d,
    0xd8,
    0xd1,
    0x95,
    0x72,
    0xac,
    0x33,
    0x86,
    0xe0
};

int main (int, char**) {
#ifndef TESTS_VERBOSE
    int stdout_redir_fd = open("/dev/null", O_WRONLY | O_APPEND);
    dup2(stdout_redir_fd,STDOUT_FILENO);
#endif
    std::cout << std::endl;

    try {
        YAPET::Key key ("JustATestPasswordForKeepingSecret");
        std::cout << " ==> ";

        for (unsigned int i = 0; i < key.size(); i++) {
            printf ("%02x", key() [i]);
	}

	std::cout <<  "\n";

        for (unsigned int i = 0; i < key.size(); i++) {
            if (key() [i] != expected_key[i]) {
                std::cout << " ##> Error in key at position " << i << std::endl;
                return 1;
            }
        }
    } catch (std::exception& ex) {
        std::cout << typeid (ex).name() << ": " << ex.what() << std::endl;
        return 1;
    }

    return 0;

}