ASN1C C/C++ Common Runtime  ASN1C v7.3.x
ASN1CTime.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-2019 Objective Systems, Inc.
3  *
4  * This software is furnished under a license and may be used and copied
5  * only in accordance with the terms of such license and with the
6  * inclusion of the above copyright notice. This software or any other
7  * copies thereof may not be provided or otherwise made available to any
8  * other person. No title to and ownership of the software is hereby
9  * transferred.
10  *
11  * The information in this software is subject to change without notice
12  * and should not be construed as a commitment by Objective Systems, Inc.
13  *
14  * PROPRIETARY NOTICE
15  *
16  * This software is an unpublished work subject to a confidentiality agreement
17  * and is protected by copyright and trade secret law. Unauthorized copying,
18  * redistribution or other use of this work is prohibited.
19  *
20  * The above notice of copyright on this source code product does not indicate
21  * any actual or intended publication of such source code.
22  *
23  *****************************************************************************/
24 
25 #ifndef __ASN1CTIME_H__
26 #define __ASN1CTIME_H__
27 
28 #ifndef _WIN32_WCE
29 #include <time.h>
30 #endif
31 #include "rtsrc/asn1CppTypes.h"
32 #include "rtsrc/ASN1TTime.h"
33 
51 //
53 // ASN1CTime
54 //
55 // ISO 8601 time and date for ITU-T X.680.
56 //
57 #ifndef _NO_UTILS_CLASSES
58 
70 #define LOG_TMERR(pctxt,stat) ((pctxt != 0) ? LOG_RTERR (pctxt, stat) : stat)
71 
84 class EXTRTCLASS ASN1CTime : public ASN1CType {
85  protected:
86  OSBOOL parsed;
87  OSBOOL derRules;
88 
89  char*& timeStr;
90  OSSIZE strSize;
91 
92  EXTRTMETHOD void checkCapacity();
93 
94  /*
95  * Returns time string pointer. NULL, if error occurred.
96  */
97  EXTRTMETHOD char*& getTimeStringPtr ();
98 
99  virtual ASN1TTime& getTimeObj () = 0;
100  virtual const ASN1TTime& getTimeObj () const = 0;
101 
102  EXTRTMETHOD ASN1CTime(char*& buf, OSSIZE bufSize, OSBOOL useDerRules);
103  EXTRTMETHOD ASN1CTime(ASN1VisibleString& buf, OSBOOL useDerRules);
104  private:
105  char timeStrBuf[MAX_TIMESTR_SIZE];
106  char* pTimeStr; // placeholder
107 
108  EXTRTMETHOD void privateInit ();
109 
110  public:
111  enum {
112  January = 1, Jan = 1,
113  February = 2, Feb = 2,
114  March = 3, Mar = 3,
115  April = 4, Apr = 4,
116  May = 5,
117  June = 6, Jun = 6,
118  July = 7, Jul = 7,
119  August = 8, Aug = 8,
120  September = 9, Sep = 9,
121  October = 10, Oct = 10,
122  November = 11, Nov = 11,
123  December = 12, Dec = 12
124  };
125 
140  EXTRTMETHOD ASN1CTime
141  (OSRTMessageBufferIF& msgBuf, char*& buf, OSSIZE bufSize,
142  OSBOOL useDerRules);
143 
159  EXTRTMETHOD ASN1CTime
160  (OSRTMessageBufferIF& msgBuf, ASN1VisibleString& buf, OSBOOL useDerRules);
161 
175  EXTRTMETHOD ASN1CTime
176  (OSRTContext& ctxt, char*& buf, OSSIZE bufSize, OSBOOL useDerRules);
177 
190  EXTRTMETHOD ASN1CTime
191  (OSRTContext& ctxt, ASN1VisibleString& buf, OSBOOL useDerRules);
192 
199  EXTRTMETHOD ASN1CTime (const ASN1CTime& original);
200 
204  EXTRTMETHOD ~ASN1CTime();
205 
217  virtual EXTRTMETHOD int getYear();
218 
233  virtual EXTRTMETHOD int getMonth();
234 
247  virtual EXTRTMETHOD int getDay();
248 
261  virtual EXTRTMETHOD int getHour();
262 
274  virtual EXTRTMETHOD int getMinute();
275 
287  virtual EXTRTMETHOD int getSecond();
288 
301  virtual EXTRTMETHOD int getFraction();
302 
314  virtual EXTRTMETHOD double getFractionAsDouble();
315 
325  virtual EXTRTMETHOD int getFractionStr(char* const pBuf, size_t bufSize);
326 
335  virtual EXTRTMETHOD int getFractionLen();
336 
352  virtual EXTRTMETHOD int getDiffHour();
353 
369  virtual EXTRTMETHOD int getDiffMinute();
370 
386  virtual EXTRTMETHOD int getDiff();
387 
397  virtual EXTRTMETHOD OSBOOL getUTC();
398 
415  virtual EXTRTMETHOD time_t getTime();
416 
421  void setDER (OSBOOL bvalue) { derRules = bvalue; }
422 
434  virtual EXTRTMETHOD int setUTC(OSBOOL utc);
435 
447  virtual EXTRTMETHOD int setYear(short year_);
448 
463  virtual EXTRTMETHOD int setMonth(short month_);
464 
477  virtual EXTRTMETHOD int setDay(short day_);
478 
491  virtual EXTRTMETHOD int setHour(short hour_);
492 
504  virtual EXTRTMETHOD int setMinute(short minute_);
505 
517  virtual EXTRTMETHOD int setSecond(short second_);
518 
534  virtual EXTRTMETHOD int setFraction(int fraction, int fracLen = -1);
535 
547  virtual EXTRTMETHOD int setFraction (double frac, int fracLen);
548 
558  virtual EXTRTMETHOD int setFraction (char const* frac);
559 
576  virtual int setTime(time_t time, OSBOOL diffTime) = 0;
577 
595  virtual EXTRTMETHOD int setDiffHour(short dhour);
596 
615  virtual EXTRTMETHOD int setDiff(short dhour, short dminute);
616 
633  virtual EXTRTMETHOD int setDiff(short inMinutes);
634 
647  virtual EXTRTMETHOD int parseString(const char* string);
648 
658  virtual EXTRTMETHOD void clear();
659 
664  virtual EXTRTMETHOD int equals (ASN1CTime&);
665 
671  EXTRTMETHOD OSSIZE getTimeStringLen ();
672 
681  EXTRTMETHOD const char* getTimeString (char* pbuf, OSSIZE bufsize);
682 
689  EXTRTMETHOD const ASN1CTime& operator = (const ASN1CTime& );
690 
696  virtual EXTRTMETHOD OSBOOL operator == (ASN1CTime&);
697 
703  virtual EXTRTMETHOD OSBOOL operator != (ASN1CTime&);
704 
710  virtual EXTRTMETHOD OSBOOL operator > (ASN1CTime&);
711 
717  virtual EXTRTMETHOD OSBOOL operator < (ASN1CTime&);
718 
724  virtual EXTRTMETHOD OSBOOL operator >= (ASN1CTime&);
725 
731  virtual EXTRTMETHOD OSBOOL operator <= (ASN1CTime&);
732 
733  protected:
739  virtual int compileString() = 0;
740 
741 } ;
742 
743 #else
744 typedef class _ASN1CTime : public ASN1CType {
745  protected:
746  _ASN1CTime(char*& buf, int bufSize, OSBOOL useDerRules) {}
747  _ASN1CTime(ASN1VisibleString& buf, OSBOOL useDerRules) {}
748  public:
749  _ASN1CTime (OSRTMessageBufferIF& msgBuf, char*& , OSSIZE, OSBOOL) :
750  ASN1CType (msgBuf) {}
751  _ASN1CTime (OSRTMessageBufferIF& msgBuf, ASN1VisibleString&, OSBOOL) :
752  ASN1CType (msgBuf) {}
753  _ASN1CTime(OSRTContext& ctxt, char*& buf, OSSIZE bufSize,
754  OSBOOL useDerRules) : ASN1CType (ctxt) {}
755  _ASN1CTime(OSRTContext& ctxt, ASN1VisibleString& buf,
756  OSBOOL useDerRules) : ASN1CType (ctxt) {}
757 } ASN1CTime;
758 
759 #endif // _NO_UTILS_CLASSES
760 
768 #endif //__ASN1CTIME_H__
769 
int operator>=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
Definition: ASN1TTime.h:71
int operator<=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
Definition: ASN1CTime.h:84
int operator<(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
#define MAX_TIMESTR_SIZE
Definition: ASN1TTime.h:34
int operator==(const ASN1OBJID &lhs, const ASN1OBJID &rhs)
Definition: asn1CppTypes.h:313
void setDER(OSBOOL bvalue)
Definition: ASN1CTime.h:421
Definition: OSRTContext.h:65
int operator!=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
int operator>(const ASN1TObjId &lhs, const ASN1TObjId &rhs)