diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/a_time.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/a_time.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c index 4ade88f065..3461660b5f 100644 --- a/src/lib/libcrypto/asn1/a_time.c +++ b/src/lib/libcrypto/asn1/a_time.c | |||
| @@ -73,55 +73,55 @@ IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) | |||
| 73 | 73 | ||
| 74 | #if 0 | 74 | #if 0 |
| 75 | int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) | 75 | int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) |
| 76 | { | 76 | { |
| 77 | if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) | 77 | if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) |
| 78 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | 78 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, |
| 79 | a->type ,V_ASN1_UNIVERSAL)); | 79 | a->type ,V_ASN1_UNIVERSAL)); |
| 80 | ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); | 80 | ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); |
| 81 | return -1; | 81 | return -1; |
| 82 | } | 82 | } |
| 83 | #endif | 83 | #endif |
| 84 | 84 | ||
| 85 | 85 | ||
| 86 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) | 86 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) |
| 87 | { | 87 | { |
| 88 | return ASN1_TIME_adj(s, t, 0, 0); | 88 | return ASN1_TIME_adj(s, t, 0, 0); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, | 91 | ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, |
| 92 | int offset_day, long offset_sec) | 92 | int offset_day, long offset_sec) |
| 93 | { | 93 | { |
| 94 | struct tm *ts; | 94 | struct tm *ts; |
| 95 | struct tm data; | 95 | struct tm data; |
| 96 | 96 | ||
| 97 | ts=OPENSSL_gmtime(&t,&data); | 97 | ts=OPENSSL_gmtime(&t,&data); |
| 98 | if (ts == NULL) | 98 | if (ts == NULL) |
| 99 | { | 99 | { |
| 100 | ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); | 100 | ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); |
| 101 | return NULL; | 101 | return NULL; |
| 102 | } | 102 | } |
| 103 | if (offset_day || offset_sec) | 103 | if (offset_day || offset_sec) |
| 104 | { | 104 | { |
| 105 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | 105 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) |
| 106 | return NULL; | 106 | return NULL; |
| 107 | } | 107 | } |
| 108 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) | 108 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) |
| 109 | return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); | 109 | return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); |
| 110 | return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); | 110 | return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | int ASN1_TIME_check(ASN1_TIME *t) | 113 | int ASN1_TIME_check(ASN1_TIME *t) |
| 114 | { | 114 | { |
| 115 | if (t->type == V_ASN1_GENERALIZEDTIME) | 115 | if (t->type == V_ASN1_GENERALIZEDTIME) |
| 116 | return ASN1_GENERALIZEDTIME_check(t); | 116 | return ASN1_GENERALIZEDTIME_check(t); |
| 117 | else if (t->type == V_ASN1_UTCTIME) | 117 | else if (t->type == V_ASN1_UTCTIME) |
| 118 | return ASN1_UTCTIME_check(t); | 118 | return ASN1_UTCTIME_check(t); |
| 119 | return 0; | 119 | return 0; |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | /* Convert an ASN1_TIME structure to GeneralizedTime */ | 122 | /* Convert an ASN1_TIME structure to GeneralizedTime */ |
| 123 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | 123 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) |
| 124 | { | 124 | { |
| 125 | ASN1_GENERALIZEDTIME *ret; | 125 | ASN1_GENERALIZEDTIME *ret; |
| 126 | char *str; | 126 | char *str; |
| 127 | int newlen; | 127 | int newlen; |
| @@ -129,20 +129,20 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE | |||
| 129 | if (!ASN1_TIME_check(t)) return NULL; | 129 | if (!ASN1_TIME_check(t)) return NULL; |
| 130 | 130 | ||
| 131 | if (!out || !*out) | 131 | if (!out || !*out) |
| 132 | { | 132 | { |
| 133 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) | 133 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) |
| 134 | return NULL; | 134 | return NULL; |
| 135 | if (out) *out = ret; | 135 | if (out) *out = ret; |
| 136 | } | 136 | } |
| 137 | else ret = *out; | 137 | else ret = *out; |
| 138 | 138 | ||
| 139 | /* If already GeneralizedTime just copy across */ | 139 | /* If already GeneralizedTime just copy across */ |
| 140 | if (t->type == V_ASN1_GENERALIZEDTIME) | 140 | if (t->type == V_ASN1_GENERALIZEDTIME) |
| 141 | { | 141 | { |
| 142 | if(!ASN1_STRING_set(ret, t->data, t->length)) | 142 | if(!ASN1_STRING_set(ret, t->data, t->length)) |
| 143 | return NULL; | 143 | return NULL; |
| 144 | return ret; | 144 | return ret; |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | /* grow the string */ | 147 | /* grow the string */ |
| 148 | if (!ASN1_STRING_set(ret, NULL, t->length + 2)) | 148 | if (!ASN1_STRING_set(ret, NULL, t->length + 2)) |
| @@ -157,10 +157,10 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE | |||
| 157 | BUF_strlcat(str, (char *)t->data, newlen); | 157 | BUF_strlcat(str, (char *)t->data, newlen); |
| 158 | 158 | ||
| 159 | return ret; | 159 | return ret; |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | 162 | int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) |
| 163 | { | 163 | { |
| 164 | ASN1_TIME t; | 164 | ASN1_TIME t; |
| 165 | 165 | ||
| 166 | t.length = strlen(str); | 166 | t.length = strlen(str); |
| @@ -170,14 +170,14 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | |||
| 170 | t.type = V_ASN1_UTCTIME; | 170 | t.type = V_ASN1_UTCTIME; |
| 171 | 171 | ||
| 172 | if (!ASN1_TIME_check(&t)) | 172 | if (!ASN1_TIME_check(&t)) |
| 173 | { | 173 | { |
| 174 | t.type = V_ASN1_GENERALIZEDTIME; | 174 | t.type = V_ASN1_GENERALIZEDTIME; |
| 175 | if (!ASN1_TIME_check(&t)) | 175 | if (!ASN1_TIME_check(&t)) |
| 176 | return 0; | 176 | return 0; |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t)) | 179 | if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t)) |
| 180 | return 0; | 180 | return 0; |
| 181 | 181 | ||
| 182 | return 1; | 182 | return 1; |
| 183 | } | 183 | } |
