ASN1C C/C++ Common Runtime  ASN1C v7.8.x
ASN1CTime.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1997-2022 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 
52 //
54 // ASN1CTime
55 //
56 // ISO 8601 time and date for ITU-T X.680.
57 //
58 #ifndef _NO_UTILS_CLASSES
59 
71 #define LOG_TMERR(pctxt,stat) ((pctxt != 0) ? LOG_RTERR (pctxt, stat) : stat)
72 
85 class EXTRTCLASS ASN1CTime : public ASN1CType {
86  protected:
87  OSBOOL parsed;
88  OSBOOL derRules;
89 
90  char*& timeStr;
91  OSSIZE strSize;
92 
93  EXTRTMETHOD void checkCapacity();
94 
95  /*
96  * Returns time string pointer. NULL, if error occurred.
97  */
98  EXTRTMETHOD char*& getTimeStringPtr ();
99 
100  virtual ASN1TTime& getTimeObj () = 0;
101  virtual const ASN1TTime& getTimeObj () const = 0;
102 
103  EXTRTMETHOD ASN1CTime(char*& buf, OSSIZE bufSize, OSBOOL useDerRules);
104  EXTRTMETHOD ASN1CTime(ASN1VisibleString& buf, OSBOOL useDerRules);
105  private:
106  char timeStrBuf[MAX_TIMESTR_SIZE];
107  char* pTimeStr; // placeholder
108 
109  EXTRTMETHOD void privateInit ();
110 
111  public:
112  enum {
113  January = 1, Jan = 1,
114  February = 2, Feb = 2,
115  March = 3, Mar = 3,
116  April = 4, Apr = 4,
117  May = 5,
118  June = 6, Jun = 6,
119  July = 7, Jul = 7,
120  August = 8, Aug = 8,
121  September = 9, Sep = 9,
122  October = 10, Oct = 10,
123  November = 11, Nov = 11,
124  December = 12, Dec = 12
125  };
126 
141  EXTRTMETHOD ASN1CTime
142  (OSRTMessageBufferIF& msgBuf, char*& buf, OSSIZE bufSize,
143  OSBOOL useDerRules);
144 
160  EXTRTMETHOD ASN1CTime
161  (OSRTMessageBufferIF& msgBuf, ASN1VisibleString& buf, OSBOOL useDerRules);
162 
176  EXTRTMETHOD ASN1CTime
177  (OSRTContext& ctxt, char*& buf, OSSIZE bufSize, OSBOOL useDerRules);
178 
191  EXTRTMETHOD ASN1CTime
192  (OSRTContext& ctxt, ASN1VisibleString& buf, OSBOOL useDerRules);
193 
200  EXTRTMETHOD ASN1CTime (const ASN1CTime& original);
201 
205  EXTRTMETHOD ~ASN1CTime();
206 
218  virtual EXTRTMETHOD int getYear();
219 
234  virtual EXTRTMETHOD int getMonth();
235 
248  virtual EXTRTMETHOD int getDay();
249 
262  virtual EXTRTMETHOD int getHour();
263 
275  virtual EXTRTMETHOD int getMinute();
276 
288  virtual EXTRTMETHOD int getSecond();
289 
302  virtual EXTRTMETHOD int getFraction();
303 
315  virtual EXTRTMETHOD double getFractionAsDouble();
316 
326  virtual EXTRTMETHOD int getFractionStr(char* const pBuf, size_t bufSize);
327 
336  virtual EXTRTMETHOD int getFractionLen();
337 
353  virtual EXTRTMETHOD int getDiffHour();
354 
370  virtual EXTRTMETHOD int getDiffMinute();
371 
387  virtual EXTRTMETHOD int getDiff();
388 
398  virtual EXTRTMETHOD OSBOOL getUTC();
399 
416  virtual EXTRTMETHOD time_t getTime();
417 
422  void setDER (OSBOOL bvalue) { derRules = bvalue; }
423 
435  virtual EXTRTMETHOD int setUTC(OSBOOL utc);
436 
448  virtual EXTRTMETHOD int setYear(short year_);
449 
464  virtual EXTRTMETHOD int setMonth(short month_);
465 
478  virtual EXTRTMETHOD int setDay(short day_);
479 
492  virtual EXTRTMETHOD int setHour(short hour_);
493 
505  virtual EXTRTMETHOD int setMinute(short minute_);
506 
518  virtual EXTRTMETHOD int setSecond(short second_);
519 
535  virtual EXTRTMETHOD int setFraction(int fraction, int fracLen = -1);
536 
548  virtual EXTRTMETHOD int setFraction (double frac, int fracLen);
549 
559  virtual EXTRTMETHOD int setFraction (char const* frac);
560 
577  virtual int setTime(time_t time, OSBOOL diffTime) = 0;
578 
596  virtual EXTRTMETHOD int setDiffHour(short dhour);
597 
616  virtual EXTRTMETHOD int setDiff(short dhour, short dminute);
617 
634  virtual EXTRTMETHOD int setDiff(short inMinutes);
635 
648  virtual EXTRTMETHOD int parseString(const char* string);
649 
659  virtual EXTRTMETHOD void clear();
660 
665  virtual EXTRTMETHOD int equals (ASN1CTime&);
666 
672  EXTRTMETHOD OSSIZE getTimeStringLen ();
673 
682  EXTRTMETHOD const char* getTimeString (char* pbuf, OSSIZE bufsize);
683 
690  EXTRTMETHOD const ASN1CTime& operator = (const ASN1CTime& );
691 
697  virtual EXTRTMETHOD OSBOOL operator == (ASN1CTime&);
698 
704  virtual EXTRTMETHOD OSBOOL operator != (ASN1CTime&);
705 
711  virtual EXTRTMETHOD OSBOOL operator > (ASN1CTime&);
712 
718  virtual EXTRTMETHOD OSBOOL operator < (ASN1CTime&);
719 
725  virtual EXTRTMETHOD OSBOOL operator >= (ASN1CTime&);
726 
732  virtual EXTRTMETHOD OSBOOL operator <= (ASN1CTime&);
733 
734  protected:
740  virtual int compileString() = 0;
741 
742 } ;
743 
744 #else
745 typedef class _ASN1CTime : public ASN1CType {
746  protected:
747  _ASN1CTime(char*& buf, int bufSize, OSBOOL useDerRules) {}
748  _ASN1CTime(ASN1VisibleString& buf, OSBOOL useDerRules) {}
749  public:
750  _ASN1CTime (OSRTMessageBufferIF& msgBuf, char*& , OSSIZE, OSBOOL) :
751  ASN1CType (msgBuf) {}
752  _ASN1CTime (OSRTMessageBufferIF& msgBuf, ASN1VisibleString&, OSBOOL) :
753  ASN1CType (msgBuf) {}
754  _ASN1CTime(OSRTContext& ctxt, char*& buf, OSSIZE bufSize,
755  OSBOOL useDerRules) : ASN1CType (ctxt) {}
756  _ASN1CTime(OSRTContext& ctxt, ASN1VisibleString& buf,
757  OSBOOL useDerRules) : ASN1CType (ctxt) {}
758 } ASN1CTime;
759 
760 #endif // _NO_UTILS_CLASSES
761  // end of ingroup asn1ctrl asn1ctime
765 
766 #endif //__ASN1CTIME_H__
767 
int operator>=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
Definition: ASN1TTime.h:66
int operator<=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
Definition: ASN1CTime.h:85
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:321
void setDER(OSBOOL bvalue)
Definition: ASN1CTime.h:422
Definition: OSRTContext.h:64
int operator!=(const ASN1TObjId &lhs, const ASN1TObjId &rhs)
int operator>(const ASN1TObjId &lhs, const ASN1TObjId &rhs)