X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FKM_util.cpp;h=2624f07fcb1bf6533153c787c9892360b07e9564;hb=f6382ee078c3d7de2dbf3a01f5624345d2c61e4a;hp=7fcd6e34b54a16636d59b5897b157341f3720e80;hpb=26e2051ac4ec9341662833d6b96016856d95c0f4;p=asdcplib.git diff --git a/src/KM_util.cpp b/src/KM_util.cpp index 7fcd6e3..2624f07 100755 --- a/src/KM_util.cpp +++ b/src/KM_util.cpp @@ -537,9 +537,6 @@ Kumu::GenRandomValue(SymmetricKey& Key) //------------------------------------------------------------------------------------------ -// read a ber value from the buffer and compare with test value. -// Advances buffer to first character after BER value. - // read a ber value from the buffer and compare with test value. // Advances buffer to first character after BER value. // @@ -605,6 +602,20 @@ static const ui64_t ber_masks[9] = 0 }; +// +ui32_t +Kumu::get_BER_length_for_value(ui64_t val) +{ + for ( ui32_t i = 0; i < 9; i++ ) + { + if ( ( val & ber_masks[i] ) == 0 ) + return i + 1; + } + + ui64Printer tmp_i(val); + DefaultLogSink().Error("BER integer encoding not supported for large value %s\n", tmp_i.c_str()); + return 0; +} // bool @@ -626,14 +637,14 @@ Kumu::write_BER(byte_t* buf, ui64_t val, ui32_t ber_len) { // sanity check BER length if ( ber_len > 9 ) { - DefaultLogSink().Error("BER size %u exceeds maximum size of 9\n", ber_len); + DefaultLogSink().Error("BER integer length %u exceeds maximum size of 9\n", ber_len); return false; } - if ( val & ber_masks[ber_len - 1] ) + if ( ( val & ber_masks[ber_len - 1] ) != 0 ) { ui64Printer tmp_i(val); - DefaultLogSink().Error("BER size %u too small for value %s\n", tmp_i.c_str()); + DefaultLogSink().Error("BER integer length %u too small for value %s\n", ber_len, tmp_i.c_str()); return false; } } @@ -774,6 +785,26 @@ Kumu::Timestamp::AddMinutes(i32_t minutes) } } +// +void +Kumu::Timestamp::AddSeconds(i32_t seconds) +{ + SYSTEMTIME current_st; + FILETIME current_ft; + ULARGE_INTEGER current_ul; + + if ( seconds != 0 ) + { + TIMESTAMP_TO_SYSTIME(*this, ¤t_st); + SystemTimeToFileTime(¤t_st, ¤t_ft); + memcpy(¤t_ul, ¤t_ft, sizeof(current_ul)); + current_ul.QuadPart += ( seconds_to_ns100(1) * (i64_t)seconds ); + memcpy(¤t_ft, ¤t_ul, sizeof(current_ft)); + FileTimeToSystemTime(¤t_ft, ¤t_st); + SYSTIME_TO_TIMESTAMP(¤t_st, *this); + } +} + #else // KM_WIN32 #include @@ -889,6 +920,23 @@ Kumu::Timestamp::AddMinutes(i32_t minutes) } } +// +void +Kumu::Timestamp::AddSeconds(i32_t seconds) +{ + Kumu::TAI::caltime ct; + Kumu::TAI::tai t; + + if ( seconds != 0 ) + { + TIMESTAMP_TO_CALTIME(*this, &ct) + t = ct; + t.add_seconds(seconds); + ct = t; + CALTIME_TO_TIMESTAMP(&ct, *this) + } +} + #endif // KM_WIN32