blob: b097cbfa42a45121fd4eee61d1da37013a716394 [file] [log] [blame]
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05001/*
Alexandre Lision907ed2e2014-02-04 10:33:09 -05002 Copyright (C) 2006-2013 Werner Dittmann
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05003
4 This program is free software: you can redistribute it and/or modify
Alexandre Lision907ed2e2014-02-04 10:33:09 -05005 it under the terms of the GNU Lesser 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
32 // set new RS1 data
33 memcpy(record.rs1, data, RS_LENGTH);
34
35 time_t validThru;
36 if (expire == -1) {
37 validThru = -1;
38 }
39 else if (expire <= 0) {
40 validThru = 0;
41 }
42 else {
43 validThru = time(NULL) + expire;
44 }
45 record.rs1Ttl = validThru;
Alexandre Lision907ed2e2014-02-04 10:33:09 -050046 resetRs2Valid();
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -050047 setRs1Valid();
48}
49
50
51bool ZIDRecordDb::isRs1NotExpired() {
52 time_t current = time(NULL);
53 time_t validThru;
54
55 validThru = record.rs1Ttl;
56
57 if (validThru == -1)
58 return true;
59 if (validThru == 0)
60 return false;
61 return (current <= validThru) ? true : false;
62}
63
64bool ZIDRecordDb::isRs2NotExpired() {
65 time_t current = time(NULL);
66 time_t validThru;
67
68 validThru = record.rs2Ttl;
69
70 if (validThru == -1)
71 return true;
72 if (validThru == 0)
73 return false;
74 return (current <= validThru) ? true : false;
75}
76
77void ZIDRecordDb::setMiTMData(const unsigned char* data) {
78 memcpy(record.mitmKey, data, RS_LENGTH);
79 setMITMKeyAvailable();
80}