navicat-keygen/openssl-lib/html/man3/ASN1_TIME_diff.html
2018-08-04 18:28:15 +08:00

123 lines
6.3 KiB
HTML

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ASN1_TIME_set</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<ul id="index">
<li><a href="#NAME">NAME</a></li>
<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
<li><a href="#NOTES">NOTES</a></li>
<li><a href="#BUGS">BUGS</a></li>
<li><a href="#EXAMPLES">EXAMPLES</a></li>
<li><a href="#RETURN-VALUES">RETURN VALUES</a></li>
<li><a href="#COPYRIGHT">COPYRIGHT</a></li>
</ul>
<h1 id="NAME">NAME</h1>
<p>ASN1_TIME_set, ASN1_TIME_adj, ASN1_TIME_check, ASN1_TIME_set_string, ASN1_TIME_print, ASN1_TIME_diff - ASN.1 Time functions</p>
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<pre><code> ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
int offset_day, long offset_sec);
int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
int ASN1_TIME_check(const ASN1_TIME *t);
int ASN1_TIME_print(BIO *b, const ASN1_TIME *s);
int ASN1_TIME_diff(int *pday, int *psec,
const ASN1_TIME *from, const ASN1_TIME *to);</code></pre>
<h1 id="DESCRIPTION">DESCRIPTION</h1>
<p>The function ASN1_TIME_set() sets the ASN1_TIME structure <b>s</b> to the time represented by the time_t value <b>t</b>. If <b>s</b> is NULL a new ASN1_TIME structure is allocated and returned.</p>
<p>ASN1_TIME_adj() sets the ASN1_TIME structure <b>s</b> to the time represented by the time <b>offset_day</b> and <b>offset_sec</b> after the time_t value <b>t</b>. The values of <b>offset_day</b> or <b>offset_sec</b> can be negative to set a time before <b>t</b>. The <b>offset_sec</b> value can also exceed the number of seconds in a day. If <b>s</b> is NULL a new ASN1_TIME structure is allocated and returned.</p>
<p>ASN1_TIME_set_string() sets ASN1_TIME structure <b>s</b> to the time represented by string <b>str</b> which must be in appropriate ASN.1 time format (for example YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ).</p>
<p>ASN1_TIME_check() checks the syntax of ASN1_TIME structure <b>s</b>.</p>
<p>ASN1_TIME_print() prints out the time <b>s</b> to BIO <b>b</b> in human readable format. It will be of the format MMM DD HH:MM:SS YYYY [GMT], for example &quot;Feb 3 00:55:52 2015 GMT&quot; it does not include a newline. If the time structure has invalid format it prints out &quot;Bad time value&quot; and returns an error.</p>
<p>ASN1_TIME_diff() sets <b>*pday</b> and <b>*psec</b> to the time difference between <b>from</b> and <b>to</b>. If <b>to</b> represents a time later than <b>from</b> then one or both (depending on the time difference) of <b>*pday</b> and <b>*psec</b> will be positive. If <b>to</b> represents a time earlier than <b>from</b> then one or both of <b>*pday</b> and <b>*psec</b> will be negative. If <b>to</b> and <b>from</b> represent the same time then <b>*pday</b> and <b>*psec</b> will both be zero. If both <b>*pday</b> and <b>*psec</b> are non-zero they will always have the same sign. The value of <b>*psec</b> will always be less than the number of seconds in a day. If <b>from</b> or <b>to</b> is NULL the current time is used.</p>
<h1 id="NOTES">NOTES</h1>
<p>The ASN1_TIME structure corresponds to the ASN.1 structure <b>Time</b> defined in RFC5280 et al. The time setting functions obey the rules outlined in RFC5280: if the date can be represented by UTCTime it is used, else GeneralizedTime is used.</p>
<p>The ASN1_TIME structure is represented as an ASN1_STRING internally and can be freed up using ASN1_STRING_free().</p>
<p>The ASN1_TIME structure can represent years from 0000 to 9999 but no attempt is made to correct ancient calendar changes (for example from Julian to Gregorian calendars).</p>
<p>Some applications add offset times directly to a time_t value and pass the results to ASN1_TIME_set() (or equivalent). This can cause problems as the time_t value can overflow on some systems resulting in unexpected results. New applications should use ASN1_TIME_adj() instead and pass the offset value in the <b>offset_sec</b> and <b>offset_day</b> parameters instead of directly manipulating a time_t value.</p>
<h1 id="BUGS">BUGS</h1>
<p>ASN1_TIME_print() currently does not print out the time zone: it either prints out &quot;GMT&quot; or nothing. But all certificates complying with RFC5280 et al use GMT anyway.</p>
<h1 id="EXAMPLES">EXAMPLES</h1>
<p>Set a time structure to one hour after the current time and print it out:</p>
<pre><code> #include &lt;time.h&gt;
#include &lt;openssl/asn1.h&gt;
ASN1_TIME *tm;
time_t t;
BIO *b;
t = time(NULL);
tm = ASN1_TIME_adj(NULL, t, 0, 60 * 60);
b = BIO_new_fp(stdout, BIO_NOCLOSE);
ASN1_TIME_print(b, tm);
ASN1_STRING_free(tm);
BIO_free(b);</code></pre>
<p>Determine if one time is later or sooner than the current time:</p>
<pre><code> int day, sec;
if (!ASN1_TIME_diff(&amp;day, &amp;sec, NULL, to))
/* Invalid time format */
if (day &gt; 0 || sec &gt; 0)
printf(&quot;Later\n&quot;);
else if (day &lt; 0 || sec &lt; 0)
printf(&quot;Sooner\n&quot;);
else
printf(&quot;Same\n&quot;);</code></pre>
<h1 id="RETURN-VALUES">RETURN VALUES</h1>
<p>ASN1_TIME_set() and ASN1_TIME_adj() return a pointer to an ASN1_TIME structure or NULL if an error occurred.</p>
<p>ASN1_TIME_set_string() returns 1 if the time value is successfully set and 0 otherwise.</p>
<p>ASN1_TIME_check() returns 1 if the structure is syntactically correct and 0 otherwise.</p>
<p>ASN1_TIME_print() returns 1 if the time is successfully printed out and 0 if an error occurred (I/O error or invalid time format).</p>
<p>ASN1_TIME_diff() returns 1 for success and 0 for failure. It can fail if the pass ASN1_TIME structure has invalid syntax for example.</p>
<h1 id="COPYRIGHT">COPYRIGHT</h1>
<p>Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.</p>
<p>Licensed under the OpenSSL license (the &quot;License&quot;). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <a href="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</a>.</p>
</body>
</html>