Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
535612a3
Commit
535612a3
authored
Jul 03, 2005
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API extended to support fractions of seconds
parent
02666199
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
204 additions
and
95 deletions
+204
-95
skeletons/GeneralizedTime.c
skeletons/GeneralizedTime.c
+110
-56
skeletons/GeneralizedTime.h
skeletons/GeneralizedTime.h
+10
-3
skeletons/tests/check-GeneralizedTime.c
skeletons/tests/check-GeneralizedTime.c
+81
-32
skeletons/tests/check-UTCTime.c
skeletons/tests/check-UTCTime.c
+2
-3
skeletons/tests/check-UTF8String.c
skeletons/tests/check-UTF8String.c
+1
-1
No files found.
skeletons/GeneralizedTime.c
View file @
535612a3
...
@@ -108,7 +108,7 @@ static time_t timegm(struct tm *tm) {
...
@@ -108,7 +108,7 @@ static time_t timegm(struct tm *tm) {
#endif
/* _EMULATE_TIMEGM */
#endif
/* _EMULATE_TIMEGM */
#ifndef __
NO_ASN_TABL
E__
#ifndef __
ASN_INTERNAL_TEST_MOD
E__
/*
/*
* GeneralizedTime basic type description.
* GeneralizedTime basic type description.
...
@@ -139,7 +139,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralizedTime = {
...
@@ -139,7 +139,7 @@ asn_TYPE_descriptor_t asn_DEF_GeneralizedTime = {
0
/* No specifics */
0
/* No specifics */
};
};
#endif
/* __
NO_ASN_TABL
E__ */
#endif
/* __
ASN_INTERNAL_TEST_MOD
E__ */
/*
/*
* Check that the time looks like the time.
* Check that the time looks like the time.
...
@@ -163,76 +163,70 @@ GeneralizedTime_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
...
@@ -163,76 +163,70 @@ GeneralizedTime_constraint(asn_TYPE_descriptor_t *td, const void *sptr,
}
}
asn_enc_rval_t
asn_enc_rval_t
GeneralizedTime_encode_der
(
asn_TYPE_descriptor_t
*
td
,
void
*
ptr
,
GeneralizedTime_encode_der
(
asn_TYPE_descriptor_t
*
td
,
void
*
s
ptr
,
int
tag_mode
,
ber_tlv_tag_t
tag
,
int
tag_mode
,
ber_tlv_tag_t
tag
,
asn_app_consume_bytes_f
*
cb
,
void
*
app_key
)
{
asn_app_consume_bytes_f
*
cb
,
void
*
app_key
)
{
GeneralizedTime_t
*
st
=
(
GeneralizedTime_t
*
)
ptr
;
GeneralizedTime_t
*
st
=
(
GeneralizedTime_t
*
)
s
ptr
;
asn_enc_rval_t
erval
;
asn_enc_rval_t
erval
;
long
fv
,
fb
;
/* seconds fraction value and base */
struct
tm
tm
;
time_t
tloc
;
/* If not canonical DER, re-encode into canonical DER. */
/*
if
(
st
->
size
&&
st
->
buf
[
st
->
size
-
1
]
!=
0x5a
)
{
* Encode as a canonical DER.
struct
tm
tm
;
*/
time_t
tloc
;
errno
=
EPERM
;
tloc
=
asn_GT2time_frac
(
st
,
&
fv
,
&
fb
,
&
tm
,
1
);
/* Recognize time */
if
(
tloc
==
-
1
&&
errno
!=
EPERM
)
/* Failed to recognize time. Fail completely. */
_ASN_ENCODE_FAILED
;
errno
=
EPERM
;
st
=
asn_time2GT_frac
(
0
,
&
tm
,
fv
,
fb
,
1
);
/* Save time canonically */
tloc
=
asn_GT2time
(
st
,
&
tm
,
1
);
/* Recognize time */
if
(
!
st
)
_ASN_ENCODE_FAILED
;
/* Memory allocation failure. */
if
(
tloc
==
-
1
&&
errno
!=
EPERM
)
{
/* Failed to recognize time. Fail completely. */
erval
.
encoded
=
-
1
;
erval
.
failed_type
=
td
;
erval
.
structure_ptr
=
ptr
;
return
erval
;
}
st
=
asn_time2GT
(
0
,
&
tm
,
1
);
/* Save time canonically */
if
(
!
st
)
{
/* Memory allocation failure. */
erval
.
encoded
=
-
1
;
erval
.
failed_type
=
td
;
erval
.
structure_ptr
=
ptr
;
return
erval
;
}
}
erval
=
OCTET_STRING_encode_der
(
td
,
st
,
tag_mode
,
tag
,
cb
,
app_key
);
erval
=
OCTET_STRING_encode_der
(
td
,
st
,
tag_mode
,
tag
,
cb
,
app_key
);
if
(
st
!=
ptr
)
{
FREEMEM
(
st
->
buf
);
FREEMEM
(
st
->
buf
);
FREEMEM
(
st
);
FREEMEM
(
st
);
}
return
erval
;
return
erval
;
}
}
#ifndef __ASN_INTERNAL_TEST_MODE__
asn_enc_rval_t
asn_enc_rval_t
GeneralizedTime_encode_xer
(
asn_TYPE_descriptor_t
*
td
,
void
*
sptr
,
GeneralizedTime_encode_xer
(
asn_TYPE_descriptor_t
*
td
,
void
*
sptr
,
int
ilevel
,
enum
xer_encoder_flags_e
flags
,
int
ilevel
,
enum
xer_encoder_flags_e
flags
,
asn_app_consume_bytes_f
*
cb
,
void
*
app_key
)
{
asn_app_consume_bytes_f
*
cb
,
void
*
app_key
)
{
OCTET_STRING_t
st
;
if
(
flags
&
XER_F_CANONICAL
)
{
if
(
flags
&
XER_F_CANONICAL
)
{
char
buf
[
32
];
GeneralizedTime_t
*
gt
;
asn_enc_rval_t
rv
;
long
fv
,
fb
;
/* fractional parts */
struct
tm
tm
;
struct
tm
tm
;
ssize_t
ret
;
errno
=
EPERM
;
errno
=
EPERM
;
if
(
asn_GT2time
((
GeneralizedTime_t
*
)
sptr
,
&
tm
,
1
)
==
-
1
if
(
asn_GT2time_frac
((
GeneralizedTime_t
*
)
sptr
,
&
fv
,
&
fb
,
&
tm
,
1
)
==
-
1
&&
errno
!=
EPERM
)
&&
errno
!=
EPERM
)
_ASN_ENCODE_FAILED
;
_ASN_ENCODE_FAILED
;
gt
=
asn_time2GT_frac
(
0
,
&
tm
,
fv
,
fb
,
1
);
if
(
!
gt
)
_ASN_ENCODE_FAILED
;
r
et
=
snprintf
(
buf
,
sizeof
(
buf
),
"%04d%02d%02d%02d%02d%02dZ"
,
r
v
=
OCTET_STRING_encode_xer_utf8
(
td
,
sptr
,
ilevel
,
flags
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
cb
,
app_key
);
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
);
asn_DEF_GeneralizedTime
.
free_struct
(
&
asn_DEF_GeneralizedTime
,
assert
(
ret
>
0
&&
ret
<
(
int
)
sizeof
(
buf
)
);
gt
,
0
);
return
rv
;
st
.
buf
=
(
uint8_t
*
)
buf
;
}
else
{
st
.
size
=
ret
;
return
OCTET_STRING_encode_xer_utf8
(
td
,
sptr
,
ilevel
,
flags
,
sptr
=
&
st
;
cb
,
app_key
)
;
}
}
return
OCTET_STRING_encode_xer_utf8
(
td
,
sptr
,
ilevel
,
flags
,
cb
,
app_key
);
}
}
#endif
/* __ASN_INTERNAL_TEST_MODE__ */
int
int
GeneralizedTime_print
(
asn_TYPE_descriptor_t
*
td
,
const
void
*
sptr
,
int
ilevel
,
GeneralizedTime_print
(
asn_TYPE_descriptor_t
*
td
,
const
void
*
sptr
,
int
ilevel
,
asn_app_consume_bytes_f
*
cb
,
void
*
app_key
)
{
asn_app_consume_bytes_f
*
cb
,
void
*
app_key
)
{
...
@@ -251,7 +245,7 @@ GeneralizedTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
...
@@ -251,7 +245,7 @@ GeneralizedTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
return
(
cb
(
"<bad-value>"
,
11
,
app_key
)
<
0
)
?
-
1
:
0
;
return
(
cb
(
"<bad-value>"
,
11
,
app_key
)
<
0
)
?
-
1
:
0
;
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
ret
=
snprintf
(
buf
,
sizeof
(
buf
),
"%04d-%02d-%02d %02d:%02d%02d (GMT)"
,
"%04d-%02d-%02d %02d:%02d
:
%02d (GMT)"
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
);
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
);
assert
(
ret
>
0
&&
ret
<
(
int
)
sizeof
(
buf
));
assert
(
ret
>
0
&&
ret
<
(
int
)
sizeof
(
buf
));
...
@@ -263,6 +257,11 @@ GeneralizedTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
...
@@ -263,6 +257,11 @@ GeneralizedTime_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
time_t
time_t
asn_GT2time
(
const
GeneralizedTime_t
*
st
,
struct
tm
*
ret_tm
,
int
as_gmt
)
{
asn_GT2time
(
const
GeneralizedTime_t
*
st
,
struct
tm
*
ret_tm
,
int
as_gmt
)
{
return
asn_GT2time_frac
(
st
,
0
,
0
,
ret_tm
,
as_gmt
);
}
time_t
asn_GT2time_frac
(
const
GeneralizedTime_t
*
st
,
long
*
frac_value
,
long
*
frac_base
,
struct
tm
*
ret_tm
,
int
as_gmt
)
{
struct
tm
tm_s
;
struct
tm
tm_s
;
uint8_t
*
buf
;
uint8_t
*
buf
;
uint8_t
*
end
;
uint8_t
*
end
;
...
@@ -270,6 +269,8 @@ asn_GT2time(const GeneralizedTime_t *st, struct tm *ret_tm, int as_gmt) {
...
@@ -270,6 +269,8 @@ asn_GT2time(const GeneralizedTime_t *st, struct tm *ret_tm, int as_gmt) {
int
gmtoff_m
=
0
;
int
gmtoff_m
=
0
;
int
gmtoff
=
0
;
/* h + m */
int
gmtoff
=
0
;
/* h + m */
int
offset_specified
=
0
;
int
offset_specified
=
0
;
long
fvalue
=
0
;
long
fbase
=
1
;
time_t
tloc
;
time_t
tloc
;
if
(
!
st
||
!
st
->
buf
)
{
if
(
!
st
||
!
st
->
buf
)
{
...
@@ -365,13 +366,21 @@ asn_GT2time(const GeneralizedTime_t *st, struct tm *ret_tm, int as_gmt) {
...
@@ -365,13 +366,21 @@ asn_GT2time(const GeneralizedTime_t *st, struct tm *ret_tm, int as_gmt) {
* ^ ^
* ^ ^
*/
*/
switch
(
*
buf
)
{
switch
(
*
buf
)
{
case
0x2C
:
case
0x2E
:
/* (.|,) */
case
0x2C
:
case
0x2E
:
/* (.|,) */
/* Fractions of seconds are not supported
/*
* by time_t or struct tm. Skip them */
* Process fractions of seconds.
*/
for
(
buf
++
;
buf
<
end
;
buf
++
)
{
for
(
buf
++
;
buf
<
end
;
buf
++
)
{
switch
(
*
buf
)
{
int
v
=
*
buf
;
switch
(
v
)
{
case
0x30
:
case
0x31
:
case
0x32
:
case
0x33
:
case
0x34
:
case
0x30
:
case
0x31
:
case
0x32
:
case
0x33
:
case
0x34
:
case
0x35
:
case
0x36
:
case
0x37
:
case
0x38
:
case
0x39
:
case
0x35
:
case
0x36
:
case
0x37
:
case
0x38
:
case
0x39
:
if
((
fbase
*
10
/
fbase
)
!=
10
)
{
/* Not enough precision, ignore */
}
else
{
fbase
*=
10
;
fvalue
=
fvalue
*
10
+
(
v
-
0x30
);
}
continue
;
continue
;
default:
default:
break
;
break
;
...
@@ -479,15 +488,29 @@ local_finish:
...
@@ -479,15 +488,29 @@ local_finish:
}
}
}
}
/* Fractions of seconds */
if
(
frac_value
)
*
frac_value
=
fvalue
;
if
(
frac_base
)
*
frac_base
=
fbase
;
return
tloc
;
return
tloc
;
}
}
GeneralizedTime_t
*
GeneralizedTime_t
*
asn_time2GT
(
GeneralizedTime_t
*
opt_gt
,
const
struct
tm
*
tm
,
int
force_gmt
)
{
asn_time2GT
(
GeneralizedTime_t
*
opt_gt
,
const
struct
tm
*
tm
,
int
force_gmt
)
{
return
asn_time2GT_frac
(
opt_gt
,
tm
,
0
,
0
,
force_gmt
);
}
GeneralizedTime_t
*
asn_time2GT_frac
(
GeneralizedTime_t
*
opt_gt
,
const
struct
tm
*
tm
,
long
frac_value
,
long
frac_base
,
int
force_gmt
)
{
struct
tm
tm_s
;
struct
tm
tm_s
;
long
gmtoff
;
long
gmtoff
;
const
unsigned
int
buf_size
=
24
;
/* 4+2+2 +2+2+2 +4 + cushion */
const
unsigned
int
buf_size
=
4
+
2
+
2
/* yyyymmdd */
+
2
+
2
+
2
/* hhmmss */
+
1
+
6
/* .ffffff */
+
1
+
4
/* +hhmm */
+
1
/* '\0' */
;
char
*
buf
;
char
*
buf
;
char
*
p
;
char
*
p
;
int
size
;
int
size
;
...
@@ -524,17 +547,48 @@ asn_time2GT(GeneralizedTime_t *opt_gt, const struct tm *tm, int force_gmt) {
...
@@ -524,17 +547,48 @@ asn_time2GT(GeneralizedTime_t *opt_gt, const struct tm *tm, int force_gmt) {
tm
->
tm_min
,
tm
->
tm_min
,
tm
->
tm_sec
tm
->
tm_sec
);
);
assert
(
size
==
14
);
if
(
size
!=
14
)
{
/* Could be assert(size == 14); */
FREEMEM
(
buf
);
errno
=
EINVAL
;
return
0
;
}
p
=
buf
+
size
;
p
=
buf
+
size
;
/*
* Deal with fractions.
*/
if
(
frac_base
>=
10
&&
frac_value
>
0
)
{
char
*
end
=
p
+
1
+
6
;
/* '.' + maximum 6 digits */
char
*
z
;
*
p
++
=
'.'
;
do
{
int
digit
;
frac_base
/=
10
;
digit
=
frac_value
/
frac_base
;
frac_value
%=
frac_base
;
*
p
++
=
digit
+
0x30
;
}
while
(
frac_base
>=
10
&&
frac_value
>
0
&&
p
<
end
);
for
(
z
=
p
-
1
;
*
z
==
0x30
;
--
z
);
/* Strip zeroes */
p
=
z
+
(
*
z
!=
'.'
);
size
=
p
-
buf
;
}
if
(
force_gmt
)
{
if
(
force_gmt
)
{
*
p
++
=
0x5a
;
/* "Z" */
*
p
++
=
0x5a
;
/* "Z" */
*
p
++
=
0
;
*
p
++
=
0
;
size
++
;
size
++
;
}
else
{
}
else
{
int
ret
=
snprintf
(
p
,
buf_size
-
size
,
"%+03ld%02ld"
,
int
ret
;
gmtoff
/
3600
,
gmtoff
%
3600
);
gmtoff
%=
86400
;
assert
(
ret
>=
5
&&
ret
<=
7
);
ret
=
snprintf
(
p
,
buf_size
-
size
,
"%+03ld%02ld"
,
gmtoff
/
3600
,
labs
(
gmtoff
%
3600
));
if
(
ret
!=
5
)
{
FREEMEM
(
buf
);
errno
=
EINVAL
;
return
0
;
}
size
+=
ret
;
size
+=
ret
;
}
}
...
...
skeletons/GeneralizedTime.h
View file @
535612a3
...
@@ -32,14 +32,21 @@ struct tm; /* <time.h> */
...
@@ -32,14 +32,21 @@ struct tm; /* <time.h> */
time_t
asn_GT2time
(
const
GeneralizedTime_t
*
,
struct
tm
*
_optional_tm4fill
,
time_t
asn_GT2time
(
const
GeneralizedTime_t
*
,
struct
tm
*
_optional_tm4fill
,
int
as_gmt
);
int
as_gmt
);
/* A version of the above function also returning the fractions of seconds */
time_t
asn_GT2time_frac
(
const
GeneralizedTime_t
*
,
long
*
frac_value
,
long
*
frac_base
,
/* (value/base) */
struct
tm
*
_optional_tm4fill
,
int
as_gmt
);
/*
/*
* Convert a struct tm into GeneralizedTime.
* Convert a struct tm into GeneralizedTime.
* If _
_opt
_gt is not given, this function will try to allocate one.
* If _
optional
_gt is not given, this function will try to allocate one.
* If force_gmt is given, the resulting GeneralizedTime will be forced
* If force_gmt is given, the resulting GeneralizedTime will be forced
* into a GMT time zone (encoding ends with a "Z").
* into a GMT time zone (encoding ends with a "Z").
* On error, this function returns 0 and sets errno.
* On error, this function returns 0 and sets errno.
*/
*/
GeneralizedTime_t
*
asn_time2GT
(
GeneralizedTime_t
*
__opt_gt
,
const
struct
tm
*
,
GeneralizedTime_t
*
asn_time2GT
(
GeneralizedTime_t
*
_optional_gt
,
int
force_gmt
);
const
struct
tm
*
,
int
force_gmt
);
GeneralizedTime_t
*
asn_time2GT_frac
(
GeneralizedTime_t
*
_optional_gt
,
const
struct
tm
*
,
long
frac_value
,
long
frac_base
,
int
force_gmt
);
#endif
/* _GeneralizedTime_H_ */
#endif
/* _GeneralizedTime_H_ */
skeletons/tests/check-GeneralizedTime.c
View file @
535612a3
#define __
NO_ASN_TABL
E__
#define __
ASN_INTERNAL_TEST_MOD
E__
#include <GeneralizedTime.c>
#include <GeneralizedTime.c>
#include <constraints.c>
#include <constraints.c>
static
void
static
void
check
(
char
*
time_str
,
time_t
expect
,
int
as_gmt
)
{
recognize
(
char
*
time_str
,
time_t
expect
,
int
as_gmt
)
{
GeneralizedTime_t
gt
;
GeneralizedTime_t
gt
;
struct
tm
tm
;
struct
tm
tm
;
time_t
tloc
;
time_t
tloc
;
long
fv
,
fb
;
gt
.
buf
=
time_str
;
gt
.
buf
=
(
uint8_t
*
)
time_str
;
gt
.
size
=
strlen
(
time_str
);
gt
.
size
=
strlen
(
time_str
);
tloc
=
asn_GT2time
(
&
gt
,
&
tm
,
as_gmt
);
tloc
=
asn_GT2time
_frac
(
&
gt
,
&
fv
,
&
fb
,
&
tm
,
as_gmt
);
printf
(
"%s: [%s] -> %ld == %ld
\n
"
,
printf
(
"%s: [%s] -> %ld == %ld
\n
"
,
as_gmt
?
"GMT"
:
"ofs"
,
time_str
,
(
long
)
tloc
,
(
long
)
expect
);
as_gmt
?
"GMT"
:
"ofs"
,
time_str
,
(
long
)
tloc
,
(
long
)
expect
);
if
(
tloc
!=
-
1
)
{
if
(
tloc
!=
-
1
)
{
printf
(
"
\t
%04d-%02d-%02dT%02d:%02d:%02d%+03ld%02ld
\n
"
,
printf
(
"
\t
%04d-%02d-%02dT%02d:%02d:%02d
(.%ld/%ld)
%+03ld%02ld
\n
"
,
tm
.
tm_year
+
1900
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_min
,
tm
.
tm_sec
,
tm
.
tm_sec
,
fv
,
fb
,
(
GMTOFF
(
tm
)
/
3600
),
(
GMTOFF
(
tm
)
/
3600
),
labs
(
GMTOFF
(
tm
)
%
3600
)
labs
(
GMTOFF
(
tm
)
%
3600
)
);
);
assert
(
fb
<
100
||
(
fb
%
100
)
==
0
);
}
}
assert
(
tloc
==
expect
);
assert
(
tloc
==
expect
);
...
@@ -33,11 +36,11 @@ check(char *time_str, time_t expect, int as_gmt) {
...
@@ -33,11 +36,11 @@ check(char *time_str, time_t expect, int as_gmt) {
assert
(
tloc
==
-
1
||
as_gmt
==
0
||
GMTOFF
(
tm
)
==
0
);
assert
(
tloc
==
-
1
||
as_gmt
==
0
||
GMTOFF
(
tm
)
==
0
);
#endif
#endif
if
(
!
as_gmt
)
check
(
time_str
,
expect
,
1
);
if
(
!
as_gmt
)
recognize
(
time_str
,
expect
,
1
);
}
}
static
void
static
void
rcheck
(
time_t
tloc
,
const
char
*
expect
,
int
force_gmt
)
{
encode
(
time_t
tloc
,
const
char
*
expect
,
int
force_gmt
)
{
GeneralizedTime_t
*
gt
;
GeneralizedTime_t
*
gt
;
struct
tm
tm
,
*
tmp
;
struct
tm
tm
,
*
tmp
;
...
@@ -49,51 +52,97 @@ rcheck(time_t tloc, const char *expect, int force_gmt) {
...
@@ -49,51 +52,97 @@ rcheck(time_t tloc, const char *expect, int force_gmt) {
assert
(
expect
);
assert
(
expect
);
printf
(
"[%s] vs [%s] (%d)
\n
"
,
printf
(
"[%s] vs [%s] (%d)
\n
"
,
gt
->
buf
,
expect
,
force_gmt
);
gt
->
buf
,
expect
,
force_gmt
);
assert
(
gt
->
size
==
(
int
)
strlen
(
gt
->
buf
));
assert
(
gt
->
size
==
(
int
)
strlen
(
(
char
*
)
gt
->
buf
));
assert
(
!
strcmp
(
gt
->
buf
,
expect
));
assert
(
!
strcmp
(
(
char
*
)
gt
->
buf
,
expect
));
}
else
{
}
else
{
assert
(
!
expect
);
assert
(
!
expect
);
}
}
}
}
static
void
recode
(
char
*
time_str
,
const
char
*
expect
)
{
long
frac_value
,
frac_base
;
GeneralizedTime_t
gt
;
struct
tm
tm
;
time_t
tloc
;
gt
.
buf
=
(
uint8_t
*
)
time_str
;
gt
.
size
=
strlen
(
time_str
);
tloc
=
asn_GT2time_frac
(
&
gt
,
&
frac_value
,
&
frac_base
,
&
tm
,
1
);
assert
(
tloc
!=
-
1
);
gt
.
buf
=
0
;
asn_time2GT_frac
(
&
gt
,
&
tm
,
frac_value
,
frac_base
,
1
);
assert
(
gt
.
buf
);
printf
(
"[%s] => [%s] == [%s]
\n
"
,
time_str
,
gt
.
buf
,
expect
);
assert
(
strcmp
((
char
*
)
gt
.
buf
,
expect
)
==
0
);
FREEMEM
(
gt
.
buf
);
}
int
int
main
(
int
ac
,
char
**
av
)
{
main
(
int
ac
,
char
**
av
)
{
(
void
)
av
;
(
void
)
av
;
check
(
"200401250"
,
-
1
,
0
);
recognize
(
"200401250"
,
-
1
,
0
);
check
(
"2004012509300"
,
-
1
,
0
);
recognize
(
"2004012509300"
,
-
1
,
0
);
check
(
"20040125093000-"
,
-
1
,
0
);
recognize
(
"20040125093000-"
,
-
1
,
0
);
check
(
"20040125093007-0"
,
-
1
,
0
);
recognize
(
"20040125093007-0"
,
-
1
,
0
);
check
(
"20040125093007-080"
,
-
1
,
0
);
recognize
(
"20040125093007-080"
,
-
1
,
0
);
check
(
"200401250930.01Z"
,
-
1
,
0
);
recognize
(
"200401250930.01Z"
,
-
1
,
0
);
/* These six are from X.690:11.7.5 */
/* These six are from X.690:11.7.5 */
check
(
"19920520240000Z"
,
-
1
,
0
);
/* midnight represented incorrectly */
recognize
(
"19920520240000Z"
,
-
1
,
0
);
/* midnight represented incorrectly */
//check("19920622123421.0Z", -1, 0); /* spurious trailing zeros */
recognize
(
"19920622123421.0Z"
,
709216461
,
0
);
/* spurious trailing zeros */
//check("19920722132100.30Z", -1, 0); /* spurious trailing zeros */
recognize
(
"19920722132100.30Z"
,
711811260
,
0
);
/* spurious trailing zeros */
check
(
"19920521000000Z"
,
706406400
,
0
);
recognize
(
"19920521000000Z"
,
706406400
,
0
);
check
(
"19920622123421Z"
,
709216461
,
0
);
recognize
(
"19920622123421Z"
,
709216461
,
0
);
check
(
"19920722132100.3Z"
,
711811260
,
0
);
recognize
(
"19920722132100.3Z"
,
711811260
,
0
);
recognize
(
"20040125093007Z"
,
1075023007
,
0
);
recognize
(
"20040125093007+00"
,
1075023007
,
0
);
recognize
(
"20040125093007.01+0000"
,
1075023007
,
0
);
recognize
(
"20040125093007,1+0000"
,
1075023007
,
0
);
recognize
(
"20040125093007-0800"
,
1075051807
,
0
);
check
(
"20040125093007Z"
,
1075023007
,
0
);
recognize
(
"19920722132100.123000123Z"
,
711811260
,
0
);
check
(
"20040125093007+00"
,
1075023007
,
0
);
recognize
(
"19920722132100.1230000123Z"
,
711811260
,
0
);
check
(
"20040125093007.01+0000"
,
1075023007
,
0
);
recognize
(
"19920722132100.12300000123Z"
,
711811260
,
0
);
check
(
"20040125093007,1+0000"
,
1075023007
,
0
);
check
(
"20040125093007-0800"
,
1075051807
,
0
);
rcheck
(
1075023007
,
"20040125093007Z"
,
1
);
encode
(
1075023007
,
"20040125093007Z"
,
1
);
if
(
ac
>
1
)
{
if
(
ac
>
1
)
{
/* These will be valid only inside PST time zone */
/* These will be valid only inside PST time zone */
check
(
"20040125093007"
,
1075051807
,
0
);
recognize
(
"20040125093007"
,
1075051807
,
0
);
check
(
"200401250930"
,
1075051800
,
0
);
recognize
(
"200401250930"
,
1075051800
,
0
);
check
(
"20040125093000,01"
,
1075051800
,
0
);
recognize
(
"20040125093000,01"
,
1075051800
,
0
);
check
(
"20040125093000,1234"
,
1075051800
,
0
);
recognize
(
"20040125093000,1234"
,
1075051800
,
0
);
rcheck
(
1075023007
,
"20040125013007-0800"
,
0
);
encode
(
1075023007
,
"20040125013007-0800"
,
0
);
recode
(
"20050702123312"
,
"20050702193312Z"
);
}
}
recode
(
"20050702123312Z"
,
"20050702123312Z"
);
recode
(
"20050702123312+01"
,
"20050702113312Z"
);
recode
(
"20050702123312,0+01"
,
"20050702113312Z"
);
recode
(
"20050702123312,1+01"
,
"20050702113312.1Z"
);
recode
(
"20050702123312.01+01"
,
"20050702113312.01Z"
);
recode
(
"20050702123312.00+01"
,
"20050702113312Z"
);
recode
(
"20050702123312.30+01"
,
"20050702113312.3Z"
);
recode
(
"20050702123312,30000+01"
,
"20050702113312.3Z"
);
recode
(
"20050702123312,300000000+01"
,
"20050702113312.3Z"
);
recode
(
"20050702123312.123456+01"
,
"20050702113312.123456Z"
);
recode
(
"20050702123312.1234567+01"
,
"20050702113312.123456Z"
);
recode
(
"20050702123312.12345678+01"
,
"20050702113312.123456Z"
);
recode
(
"20050702123312.123456789+01"
,
"20050702113312.123456Z"
);
recode
(
"20050702123312.000001+01"
,
"20050702113312.000001Z"
);
recode
(
"20050702123312.0000001Z"
,
"20050702123312Z"
);
recode
(
"20050702123312.0080010+1056"
,
"20050702013712.008001Z"
);
return
0
;
return
0
;
}
}
...
...
skeletons/tests/check-UTCTime.c
View file @
535612a3
#define __
NO_ASN_TABL
E__
#define __
ASN_INTERNAL_TEST_MOD
E__
#include <GeneralizedTime.c>
#include <GeneralizedTime.c>
#define __NO_ASN_TABLE__
#include <UTCTime.c>
#include <UTCTime.c>
#include <constraints.c>
#include <constraints.c>
...
@@ -10,7 +9,7 @@ check(char *time_str, time_t sample, int as_gmt) {
...
@@ -10,7 +9,7 @@ check(char *time_str, time_t sample, int as_gmt) {
struct
tm
tm
;
struct
tm
tm
;
time_t
tloc
;
time_t
tloc
;
gt
.
buf
=
time_str
;
gt
.
buf
=
(
uint8_t
*
)
time_str
;
gt
.
size
=
strlen
(
time_str
);
gt
.
size
=
strlen
(
time_str
);
tloc
=
asn_UT2time
(
&
gt
,
&
tm
,
as_gmt
);
tloc
=
asn_UT2time
(
&
gt
,
&
tm
,
as_gmt
);
...
...
skeletons/tests/check-UTF8String.c
View file @
535612a3
...
@@ -43,7 +43,7 @@ check_speed() {
...
@@ -43,7 +43,7 @@ check_speed() {
int
ret
;
int
ret
;
int
i
;
int
i
;
st
.
buf
=
long_test
;
st
.
buf
=
(
uint8_t
*
)
long_test
;
st
.
size
=
sizeof
(
long_test
)
-
1
;
st
.
size
=
sizeof
(
long_test
)
-
1
;
ret
=
UTF8String_length
(
&
st
);
ret
=
UTF8String_length
(
&
st
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment