epan: Add ENC_ISO_8601_DATE_TIME_BASIC

Add the ISO 8601 Basic date time format as another string time
option. This could be used for e.g. ASN.1 GeneralizedTime.
Add tests for it.
This commit is contained in:
John Thacker 2021-12-01 23:13:21 -05:00
parent 871895f95a
commit aadf4efcbe
7 changed files with 66 additions and 11 deletions

View File

@ -88,6 +88,7 @@ static ws_enum_t all_enums[] = {
ENUM(ENC_ISO_646_IRV),
ENUM(ENC_ISO_8601_DATE),
ENUM(ENC_ISO_8601_DATE_TIME),
ENUM(ENC_ISO_8601_DATE_TIME_BASIC),
ENUM(ENC_ISO_8601_TIME),
ENUM(ENC_ISO_8859_1),
ENUM(ENC_ISO_8859_10),

View File

@ -4207,23 +4207,26 @@ proto_tree_add_time_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi!");
DISSECTOR_ASSERT_FIELD_TYPE_IS_TIME(hfinfo);
/* length has to be -1 or > 0 regardless of encoding */
if (length < -1 || length == 0) {
REPORT_DISSECTOR_BUG("Invalid length %d passed to proto_tree_add_time_item",
length);
}
time_stamp.secs = 0;
time_stamp.nsecs = 0;
nstime_set_zero(&time_stamp);
if (encoding & ENC_STR_TIME_MASK) {
DISSECTOR_ASSERT_FIELD_TYPE(hfinfo, FT_ABSOLUTE_TIME);
/* The only string format that could be a relative time is
* ENC_ISO_8601_TIME, and that is treated as an absolute time
* relative to "now" currently.
*/
tvb_get_string_time(tvb, start, length, encoding, &time_stamp, endoff);
/* grab the errno now before it gets overwritten */
saved_err = errno;
}
else {
DISSECTOR_ASSERT_FIELD_TYPE_IS_TIME(hfinfo);
const gboolean is_relative = (hfinfo->type == FT_RELATIVE_TIME) ? TRUE : FALSE;
tvb_ensure_bytes_exist(tvb, start, length);

View File

@ -613,13 +613,14 @@ void proto_report_dissector_bug(const char *format, ...)
* you can't do both at the same time. They must not, however,
* overlap with the character encoding values.
*/
#define ENC_ISO_8601_DATE 0x00010000
#define ENC_ISO_8601_TIME 0x00020000
#define ENC_ISO_8601_DATE_TIME 0x00030000
#define ENC_RFC_822 0x00040000
#define ENC_RFC_1123 0x00080000
#define ENC_ISO_8601_DATE 0x00010000
#define ENC_ISO_8601_TIME 0x00020000
#define ENC_ISO_8601_DATE_TIME 0x00030000
#define ENC_RFC_822 0x00040000
#define ENC_RFC_1123 0x00080000
#define ENC_ISO_8601_DATE_TIME_BASIC 0x00100000
/* a convenience macro for the above - for internal use only */
#define ENC_STR_TIME_MASK 0x000F0000
#define ENC_STR_TIME_MASK 0x001F0000
/*
* Encodings for variable-length integral types.

View File

@ -1796,6 +1796,11 @@ tvb_get_string_time(tvbuff_t *tvb, const gint offset, const gint length,
errno = 0;
end = ptr + num_chars;
}
} else if ((encoding & ENC_ISO_8601_DATE_TIME_BASIC) == ENC_ISO_8601_DATE_TIME_BASIC) {
if ((num_chars = iso8601_to_nstime(ns, ptr, ISO8601_DATETIME_BASIC))) {
errno = 0;
end = ptr + num_chars;
}
} else {
memset(&tm, 0, sizeof(tm));
tm.tm_isdst = -1;

View File

@ -130,6 +130,7 @@
["ENC_EBCDIC"] = 46,
["ENC_ISO_8601_DATE"] = 65536,
["ENC_ISO_8601_DATE_TIME"] = 196608,
["ENC_ISO_8601_DATE_TIME_BASIC"] = 1048576,
["ENC_ISO_8601_TIME"] = 131072,
["ENC_ISO_8859_1"] = 10,
["ENC_ISO_8859_10"] = 28,

View File

@ -54,7 +54,7 @@ end
-- number of verifyFields() * (1 + number of fields) +
-- number of verifyResults() * (1 + 2 * number of values)
--
local taptests = { [FRAME]=4, [OTHER]=353 }
local taptests = { [FRAME]=4, [OTHER]=413 }
local function getResults()
print("\n-----------------------------\n")
@ -882,6 +882,47 @@ function test_proto.dissector(tvbuf,pktinfo,root)
verifyResults("add_pfield-rfc1123-local", autc_match_values)
----------------------------------------
testing(OTHER, "tree:add_packet_field Time string ENC_ISO_8601_DATE_TIME_BASIC")
resetResults()
autc_match_values = {}
local datetimestring1 = "20130301T221448+0000" -- this is 1362176088 seconds epoch time
local tvb1 = ByteArray.new(datetimestring1, true):tvb("Date_Time string 1")
local datetimestring2 = " 20130301171448+0500" -- this is 1362176088 seconds epoch time
local tvb2 = ByteArray.new(datetimestring2 .. " foobar", true):tvb("Date_Time string 2")
local datetimestring3 = " 20130301T1644+0530" -- this is 1362176040 seconds epoch time
local tvb3 = ByteArray.new(datetimestring3, true):tvb("Date_Time string 3")
local datetimestring4 = "20130302 014400-0330" -- this is 1362176040 seconds epoch time
local tvb4 = ByteArray.new(datetimestring4, true):tvb("Date_Time string 4")
local datetimestring5 = "20130301T221448Z" -- this is 1362176088 seconds epoch time
local tvb5 = ByteArray.new(datetimestring5, true):tvb("Date_Time string 5")
local datetimestring6 = "201303012214Z" -- this is 1362176040 seconds epoch time
local tvb6 = ByteArray.new(datetimestring6, true):tvb("Date_Time string 6")
execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb1:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
addMatch( NSTime( 1362176088, 0), string.len(datetimestring1))
execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb2:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
addMatch( NSTime( 1362176088, 0), string.len(datetimestring2))
execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb3:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
addMatch( NSTime( 1362176040, 0), string.len(datetimestring3))
execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb4:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
addMatch( NSTime( 1362176040, 0), string.len(datetimestring4))
execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb5:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
addMatch( NSTime( 1362176088, 0), string.len(datetimestring5))
execute ("add_pfield-datetime-local", treeAddPField ( tree, AUTC, tvb6:range(), ENC_ISO_8601_DATE_TIME_BASIC) )
addMatch( NSTime( 1362176040, 0), string.len(datetimestring6))
verifyFields("time.ABSOLUTE_UTC", autc_match_fields)
verifyResults("add_pfield-datetime-local", autc_match_values)
----------------------------------------
testing(OTHER, "TvbRange subsets")

View File

@ -92,6 +92,9 @@ tm_is_valid(struct tm *tm)
if (tm->tm_hour < 0 || tm->tm_hour > 23) {
return FALSE;
}
/* XXX: ISO 8601 and others allow 24:00:00 for end of day, perhaps that
* one case should be allowed?
*/
if (tm->tm_min < 0 || tm->tm_min > 59) {
return FALSE;
}