ASN1C C/C++ Common Runtime  ASN1C v7.2.x
ASN1CTime.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-2018 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 // Author Artem Bolgar.
58 //
59 #ifndef _NO_UTILS_CLASSES
60 
72 #define LOG_TMERR(pctxt,stat) ((pctxt != 0) ? LOG_RTERR (pctxt, stat) : stat)
73 
86 class EXTRTCLASS ASN1CTime : public ASN1CType {
87  protected:
88  OSBOOL parsed;
89  OSBOOL derRules;
90 
91  char*& timeStr;
92  int strSize;
93 
94  EXTRTMETHOD void checkCapacity();
95 
96  /*
97  * Returns time string pointer. NULL, if error occurred.
98  */
99  EXTRTMETHOD char*& getTimeStringPtr ();
100 
101  virtual ASN1TTime& getTimeObj () = 0;
102  virtual const ASN1TTime& getTimeObj () const = 0;
103 
104  EXTRTMETHOD ASN1CTime(char*& buf, int bufSize, OSBOOL useDerRules);
105  EXTRTMETHOD ASN1CTime(ASN1VisibleString& buf, OSBOOL useDerRules);
106  private:
107  char timeStrBuf[MAX_TIMESTR_SIZE];
108  char* pTimeStr; // placeholder
109 
110  EXTRTMETHOD void privateInit ();
111 
112  public:
113  enum {
114  January = 1, Jan = 1,
115  February = 2, Feb = 2,
116  March = 3, Mar = 3,
117  April = 4, Apr = 4,
118  May = 5,
119  June = 6, Jun = 6,
120  July = 7, Jul = 7,
121  August = 8, Aug = 8,
122  September = 9, Sep = 9,
123  October = 10, Oct = 10,
124  November = 11, Nov = 11,
125  December = 12, Dec = 12
126  };
127 
142  EXTRTMETHOD ASN1CTime (OSRTMessageBufferIF& msgBuf, char*& buf, int bufSize,
143  OSBOOL useDerRules);
144 
160  EXTRTMETHOD ASN1CTime (OSRTMessageBufferIF& msgBuf, ASN1VisibleString& buf,
161  OSBOOL useDerRules);
162 
163 
177  EXTRTMETHOD ASN1CTime (OSRTContext& ctxt, char*& buf, int bufSize,
178  OSBOOL useDerRules);
179 
192  EXTRTMETHOD ASN1CTime (OSRTContext& ctxt, ASN1VisibleString& buf,
193  OSBOOL useDerRules);
194 
201  EXTRTMETHOD ASN1CTime (const ASN1CTime& original);
202 
206  EXTRTMETHOD ~ASN1CTime();
207 
219  virtual EXTRTMETHOD int getYear();
220 
235  virtual EXTRTMETHOD int getMonth();
236 
249  virtual EXTRTMETHOD int getDay();
250 
263  virtual EXTRTMETHOD int getHour();
264 
276  virtual EXTRTMETHOD int getMinute();
277 
289  virtual EXTRTMETHOD int getSecond();
290 
303  virtual EXTRTMETHOD int getFraction();
304 
316  virtual EXTRTMETHOD double getFractionAsDouble();
317 
327  virtual EXTRTMETHOD int getFractionStr(char* const pBuf, size_t bufSize);
328 
337  virtual EXTRTMETHOD int getFractionLen();
338 
354  virtual EXTRTMETHOD int getDiffHour();
355 
371  virtual EXTRTMETHOD int getDiffMinute();
372 
388  virtual EXTRTMETHOD int getDiff();
389 
399  virtual EXTRTMETHOD OSBOOL getUTC();
400 
417  virtual EXTRTMETHOD time_t getTime();
418 
423  void setDER (OSBOOL bvalue) { derRules = bvalue; }
424 
436  virtual EXTRTMETHOD int setUTC(OSBOOL utc);
437 
449  virtual EXTRTMETHOD int setYear(short year_);
450 
465  virtual EXTRTMETHOD int setMonth(short month_);
466 
479  virtual EXTRTMETHOD int setDay(short day_);
480 
493  virtual EXTRTMETHOD int setHour(short hour_);
494 
506  virtual EXTRTMETHOD int setMinute(short minute_);
507 
519  virtual EXTRTMETHOD int setSecond(short second_);
520 
536  virtual EXTRTMETHOD int setFraction(int fraction, int fracLen = -1);
537 
549  virtual EXTRTMETHOD int setFraction (double frac, int fracLen);
550 
560  virtual EXTRTMETHOD int setFraction (char const* frac);
561 
578  virtual int setTime(time_t time, OSBOOL diffTime) = 0;
579 
597  virtual EXTRTMETHOD int setDiffHour(short dhour);
598 
617  virtual EXTRTMETHOD int setDiff(short dhour, short dminute);
618 
635  virtual EXTRTMETHOD int setDiff(short inMinutes);
636 
649  virtual EXTRTMETHOD int parseString(const char* string);
650 
660  virtual EXTRTMETHOD void clear();
661 
666  virtual EXTRTMETHOD int equals (ASN1CTime&);
667 
673  EXTRTMETHOD size_t getTimeStringLen ();
674 
683  EXTRTMETHOD const char* getTimeString (char* pbuf, size_t bufsize);
684 
691  EXTRTMETHOD const ASN1CTime& operator = (const ASN1CTime& );
692 
698  virtual EXTRTMETHOD OSBOOL operator == (ASN1CTime&);
699 
705  virtual EXTRTMETHOD OSBOOL operator != (ASN1CTime&);
706 
712  virtual EXTRTMETHOD OSBOOL operator > (ASN1CTime&);
713 
719  virtual EXTRTMETHOD OSBOOL operator < (ASN1CTime&);
720 
726  virtual EXTRTMETHOD OSBOOL operator >= (ASN1CTime&);
727 
733  virtual EXTRTMETHOD OSBOOL operator <= (ASN1CTime&);
734 
735  protected:
741  virtual int compileString() = 0;
742 
743 } ;
744 
745 #else
746 typedef class _ASN1CTime : public ASN1CType {
747  protected:
748  _ASN1CTime(char*& buf, int bufSize, OSBOOL useDerRules) {}
749  _ASN1CTime(ASN1VisibleString& buf, OSBOOL useDerRules) {}
750  public:
751  _ASN1CTime (OSRTMessageBufferIF& msgBuf, char*& , int, OSBOOL) :
752  ASN1CType (msgBuf) {}
753  _ASN1CTime (OSRTMessageBufferIF& msgBuf, ASN1VisibleString&, OSBOOL) :
754  ASN1CType (msgBuf) {}
755  _ASN1CTime(OSRTContext& ctxt, char*& buf, int bufSize,
756  OSBOOL useDerRules) : ASN1CType (ctxt) {}
757  _ASN1CTime(OSRTContext& ctxt, ASN1VisibleString& buf,
758  OSBOOL useDerRules) : ASN1CType (ctxt) {}
759 } ASN1CTime;
760 
761 #endif // _NO_UTILS_CLASSES
762 
770 #endif //__ASN1CTIME_H__
771 
int operator>=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
Definition: ASN1TTime.h:71
int operator<=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
Definition: ASN1CTime.h:86
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:314
void setDER(OSBOOL bvalue)
Definition: ASN1CTime.h:423
Definition: OSRTContext.h:65
int operator!=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
int operator>(const ASN1TObjId &lhs, const ASN1TObjId &rhs)