]>
git.saurik.com Git - apple/security.git/blob - Security/libsecurity_cdsa_utilities/lib/cssmdates.h
2 * Copyright (c) 2000-2004,2006,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 // Manage the Tower of Babel of CSSM dates and times.
31 #include <security_utilities/utilities.h>
32 #include <security_cdsa_utilities/cssmdata.h>
33 #include <CoreFoundation/CFDate.h>
40 // A PodWrapper for CSSM_DATE
42 class CssmDate
: public PodWrapper
<CssmDate
, CSSM_DATE
> {
45 CssmDate(const char *y
, const char *m
, const char *d
);
46 CssmDate(int y
, int m
, int d
);
48 const char *years() const { return reinterpret_cast<const char *>(Year
); }
49 const char *months() const { return reinterpret_cast<const char *>(Month
); }
50 const char *days() const { return reinterpret_cast<const char *>(Day
); }
51 char *years() { return reinterpret_cast<char *>(Year
); }
52 char *months() { return reinterpret_cast<char *>(Month
); }
53 char *days() { return reinterpret_cast<char *>(Day
); }
60 static void assign(char *dest
, int width
, const char *src
);
63 inline bool operator == (const CSSM_DATE
&d1
, const CSSM_DATE
&d2
)
64 { return !memcmp(&d1
, &d2
, sizeof(d1
)); }
66 inline bool operator != (const CSSM_DATE
&d1
, const CSSM_DATE
&d2
)
67 { return !memcmp(&d1
, &d2
, sizeof(d1
)); }
71 // Yet another CSSM date/time format is CSSM_TIMESTRING. This is
72 // defined as "char *", just so you can't use the type system
73 // to keep things sane, so we can't really PodWrap it the usual way.
74 // What *were* they thinking?
75 // The format is allegedly "yyyymmddhhmmss", and the standard says
76 // nothing about trailing null characters.
81 // A unified date-and-time object.
82 // This is based on CFDate objects and converts to various CSSM
85 class CssmUniformDate
{
89 // convert to/from CFDateRef
90 CssmUniformDate(CFDateRef ref
);
91 operator CFDateRef() const;
93 // convert to/from CFAbsoluteTime
94 CssmUniformDate(CFAbsoluteTime ct
) : mTime(ct
) { }
95 operator CFAbsoluteTime() const { return mTime
; }
97 // convert to/from CSSM_DATE
98 CssmUniformDate(const CssmDate
&src
);
99 operator CssmDate () const;
101 // convert to/from DATA format (1999-06-30_15:05:39 form)
102 CssmUniformDate(const CSSM_DATA
&src
);
103 void convertTo(CssmOwnedData
&data
) const;
105 // convert to/from CSSM_TIMESTRING format (19990630150539)
106 CssmUniformDate(const char *src
);
107 void convertTo(char *dest
, size_t length
) const;
109 // native comparisons
110 bool operator < (const CssmUniformDate
&other
) const { return mTime
< other
.mTime
; }
111 bool operator == (const CssmUniformDate
&other
) const { return mTime
== other
.mTime
; }
112 bool operator > (const CssmUniformDate
&other
) const { return mTime
> other
.mTime
; }
113 bool operator <= (const CssmUniformDate
&other
) const { return mTime
<= other
.mTime
; }
114 bool operator >= (const CssmUniformDate
&other
) const { return mTime
>= other
.mTime
; }
115 bool operator != (const CssmUniformDate
&other
) const { return mTime
!= other
.mTime
; }
118 void setFromString(const char *src
, const char *format
, size_t fieldLength
);
121 CFAbsoluteTime mTime
;
125 } // end namespace Security
127 #endif //_H_CSSMDATES