1ASN1_TIME_set(3)                    OpenSSL                   ASN1_TIME_set(3)
2
3
4

NAME

6       ASN1_TIME_set, ASN1_TIME_adj, ASN1_TIME_check, ASN1_TIME_set_string,
7       ASN1_TIME_print, ASN1_TIME_diff - ASN.1 Time functions.
8

SYNOPSIS

10        ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
11        ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
12                                 int offset_day, long offset_sec);
13        int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
14        int ASN1_TIME_check(const ASN1_TIME *t);
15        int ASN1_TIME_print(BIO *b, const ASN1_TIME *s);
16
17        int ASN1_TIME_diff(int *pday, int *psec,
18                           const ASN1_TIME *from, const ASN1_TIME *to);
19

DESCRIPTION

21       The function ASN1_TIME_set() sets the ASN1_TIME structure s to the time
22       represented by the time_t value t. If s is NULL a new ASN1_TIME
23       structure is allocated and returned.
24
25       ASN1_TIME_adj() sets the ASN1_TIME structure s to the time represented
26       by the time offset_day and offset_sec after the time_t value t.  The
27       values of offset_day or offset_sec can be negative to set a time before
28       t. The offset_sec value can also exceed the number of seconds in a day.
29       If s is NULL a new ASN1_TIME structure is allocated and returned.
30
31       ASN1_TIME_set_string() sets ASN1_TIME structure s to the time
32       represented by string str which must be in appropriate ASN.1 time
33       format (for example YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ).
34
35       ASN1_TIME_check() checks the syntax of ASN1_TIME structure s.
36
37       ASN1_TIME_print() prints out the time s to BIO b in human readable
38       format. It will be of the format MMM DD HH:MM:SS YYYY [GMT], for
39       example "Feb  3 00:55:52 2015 GMT" it does not include a newline. If
40       the time structure has invalid format it prints out "Bad time value"
41       and returns an error.
42
43       ASN1_TIME_diff() sets *pday and *psec to the time difference between
44       from and to. If to represents a time later than from then one or both
45       (depending on the time difference) of *pday and *psec will be positive.
46       If to represents a time earlier than from then one or both of *pday and
47       *psec will be negative. If to and from represent the same time then
48       *pday and *psec will both be zero.  If both *pday and *psec are non-
49       zero they will always have the same sign. The value of *psec will
50       always be less than the number of seconds in a day. If from or to is
51       NULL the current time is used.
52

NOTES

54       The ASN1_TIME structure corresponds to the ASN.1 structure Time defined
55       in RFC5280 et al. The time setting functions obey the rules outlined in
56       RFC5280: if the date can be represented by UTCTime it is used, else
57       GeneralizedTime is used.
58
59       The ASN1_TIME structure is represented as an ASN1_STRING internally and
60       can be freed up using ASN1_STRING_free().
61
62       The ASN1_TIME structure can represent years from 0000 to 9999 but no
63       attempt is made to correct ancient calendar changes (for example from
64       Julian to Gregorian calendars).
65
66       Some applications add offset times directly to a time_t value and pass
67       the results to ASN1_TIME_set() (or equivalent). This can cause problems
68       as the time_t value can overflow on some systems resulting in
69       unexpected results.  New applications should use ASN1_TIME_adj()
70       instead and pass the offset value in the offset_sec and offset_day
71       parameters instead of directly manipulating a time_t value.
72

BUGS

74       ASN1_TIME_print() currently does not print out the time zone: it either
75       prints out "GMT" or nothing. But all certificates complying with
76       RFC5280 et al use GMT anyway.
77

EXAMPLES

79       Set a time structure to one hour after the current time and print it
80       out:
81
82        #include <time.h>
83        #include <openssl/asn1.h>
84        ASN1_TIME *tm;
85        time_t t;
86        BIO *b;
87        t = time(NULL);
88        tm = ASN1_TIME_adj(NULL, t, 0, 60 * 60);
89        b = BIO_new_fp(stdout, BIO_NOCLOSE);
90        ASN1_TIME_print(b, tm);
91        ASN1_STRING_free(tm);
92        BIO_free(b);
93
94       Determine if one time is later or sooner than the current time:
95
96        int day, sec;
97
98        if (!ASN1_TIME_diff(&day, &sec, NULL, to))
99               /* Invalid time format */
100
101        if (day > 0 || sec > 0)
102          printf("Later\n");
103        else if (day < 0 || sec < 0)
104          printf("Sooner\n");
105        else
106          printf("Same\n");
107

RETURN VALUES

109       ASN1_TIME_set() and ASN1_TIME_adj() return a pointer to an ASN1_TIME
110       structure or NULL if an error occurred.
111
112       ASN1_TIME_set_string() returns 1 if the time value is successfully set
113       and 0 otherwise.
114
115       ASN1_TIME_check() returns 1 if the structure is syntactically correct
116       and 0 otherwise.
117
118       ASN1_TIME_print() returns 1 if the time is successfully printed out and
119       0 if an error occurred (I/O error or invalid time format).
120
121       ASN1_TIME_diff() returns 1 for sucess and 0 for failure. It can fail if
122       the pass ASN1_TIME structure has invalid syntax for example.
123
124
125
1261.0.2k                            2017-01-26                  ASN1_TIME_set(3)
Impressum