File: partdec.h

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 (137 lines) | stat: -rw-r--r-- 4,514 bytes parent folder | download
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// -*- c++ -*-
//
// $Id: partdec.h 2719 2009-08-20 01:30:25Z rafi $
//
// Copyright (C) 2008, 2009  Rafael Ostertag
//
// This file is part of YAPET.
//
// YAPET is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// YAPET.  If not, see <http://www.gnu.org/licenses/>.
//
// Additional permission under GNU GPL version 3 section 7
//
// If you modify this program, or any covered work, by linking or combining it
// with the OpenSSL project's OpenSSL library (or a modified version of that
// library), containing parts covered by the terms of the OpenSSL or SSLeay
// licenses, Rafael Ostertag grants you additional permission to convey the
// resulting work.  Corresponding Source for a non-source form of such a
// combination shall include the source code for the parts of OpenSSL used as
// well as that of the covered work.
//

#ifndef _PARTDEC_H
#define _PARTDEC_H

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif

#include "record.h"
#include "key.h"
#include "yapetexception.h"
#include "bdbuffer.h"
#include "structs.h"

namespace YAPET {
    /**
     * @brief Holds a partially decrypted record
     *
     * Partially decrypted records have their name stored in plain
     * text. The other fields of the password record remain
     * encrypted. This class is used for convenience. It relieves the
     * user of writing code for decrypting the record in order to get
     * only the record name.
     *
     * The \c File class uses this class when reading and returning
     * the records stored in a file. It also expects a list of \c
     * PartDec object when writing password records to the file.
     *
     * The encrypted data is also attached to this class as a \c BDBuffer.
     */
    class PartDec {
        private:
            /**
             * @brief The record name in plain text
             *
             * The password record name in plain text.
             */
            uint8_t name[NAME_SIZE];
            /**
             * @brief The encrypted password record.
             *
             * This is the encrypted password record.
             */
            BDBuffer enc_data;

        public:
            PartDec();

            PartDec (BDBuffer& bd,
                     const Key& key) throw (YAPETException);

            PartDec (Record<PasswordRecord>& pr,
                     const Key& key) throw (YAPETException);

            PartDec (const PartDec& pd);

            ~PartDec();

            void setRecord (Record<PasswordRecord>& pr,
                            const Key& key) throw (YAPETException);
            /**
             * @brief Get the encrypted password record.
             *
             * Gets the encrypted password record associated with this
             * object.
             *
             * @return reference to the \c BDBuffer holding the
             * encrypted data.
             */
            inline const BDBuffer& getEncRecord() const {
                return enc_data;
            }
            /**
             * @brief Get the plain text name of the password record.
             *
             * Returns the pointer to the plain text name of the
             * password record.
             *
             * @return pointer to the buffer holding the plain text
             * name of the password record.
             */
            inline const uint8_t* getName() const {
                return name;
            }
            /**
             * This method has been added because \c
             * YAPET::UI::ListWidget expects the object assigned to the
             * list being displayed to have a public method called \c
             * c_str().
             *
             * @copydoc getName()
             */
            inline const char* c_str() const {
                return (char*) name;
            }
            const PartDec& operator= (const PartDec& pd);

            bool operator< (const PartDec& pd) const;
    };
}

#endif // _PARTDEC_H