blob: 0bd91f0b3052f767287da5f279e948c8102e29d7 [file] [log] [blame]
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05001/*
Alexandre Lisionddd731e2014-01-31 11:50:08 -05002 Copyright (C) 2006-2007 Werner Dittmann
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05003
4 This program is free software: you can redistribute it and/or modify
Alexandre Lisionddd731e2014-01-31 11:50:08 -05005 it under the terms of the GNU General Public License as published by
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05006 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18/*
19 * Authors: Werner Dittmann <Werner.Dittmann@t-online.de>
20 */
21
22#include <time.h>
23
24#include <libzrtpcpp/ZIDRecordDb.h>
25
26void ZIDRecordDb::setNewRs1(const unsigned char* data, int32_t expire) {
27
28 // shift RS1 data into RS2 position
29 memcpy(record.rs2, record.rs1, RS_LENGTH);
30 record.rs2Ttl = record.rs1Ttl;
31
Alexandre Lisionddd731e2014-01-31 11:50:08 -050032 // now propagate flags as well
33 if (isRs1Valid()) {
34 setRs2Valid();
35 }
36
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050037 // set new RS1 data
38 memcpy(record.rs1, data, RS_LENGTH);
39
40 time_t validThru;
41 if (expire == -1) {
42 validThru = -1;
43 }
44 else if (expire <= 0) {
45 validThru = 0;
46 }
47 else {
48 validThru = time(NULL) + expire;
49 }
50 record.rs1Ttl = validThru;
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050051 setRs1Valid();
52}
53
54
55bool ZIDRecordDb::isRs1NotExpired() {
56 time_t current = time(NULL);
57 time_t validThru;
58
59 validThru = record.rs1Ttl;
60
61 if (validThru == -1)
62 return true;
63 if (validThru == 0)
64 return false;
65 return (current <= validThru) ? true : false;
66}
67
68bool ZIDRecordDb::isRs2NotExpired() {
69 time_t current = time(NULL);
70 time_t validThru;
71
72 validThru = record.rs2Ttl;
73
74 if (validThru == -1)
75 return true;
76 if (validThru == 0)
77 return false;
78 return (current <= validThru) ? true : false;
79}
80
81void ZIDRecordDb::setMiTMData(const unsigned char* data) {
82 memcpy(record.mitmKey, data, RS_LENGTH);
83 setMITMKeyAvailable();
84}