From 264824628f58a1668b54252babb1add4d3c7eb79 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Mon, 8 Apr 2013 14:07:23 +0200 Subject: [PATCH 1/3] rhbz#918079 always return 40 hexa digits (cherry picked from commit 8e66145d204f7d053549b7cc28aef6863cfd38c8) --- src/libcmis/test-xmlutils.cxx | 12 ++++++++++-- src/libcmis/xml-utils.cxx | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libcmis/test-xmlutils.cxx b/src/libcmis/test-xmlutils.cxx index dd5082f..0e527ad 100644 --- a/src/libcmis/test-xmlutils.cxx +++ b/src/libcmis/test-xmlutils.cxx @@ -431,8 +431,16 @@ void XmlTest::propertyIntegerAsXmlTest( ) void XmlTest::sha1Test( ) { - string actual = libcmis::sha1( "Hello" ); - CPPUNIT_ASSERT_EQUAL( string( "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0" ), actual ); + { + string actual = libcmis::sha1( "Hello" ); + CPPUNIT_ASSERT_EQUAL( string( "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0" ), actual ); + } + + { + // check correct width + string actual = libcmis::sha1( "35969137" ); + CPPUNIT_ASSERT_EQUAL( string( "0d93546909cfeb5c00089202104df3980000ec9f" ), actual ); + } } CPPUNIT_TEST_SUITE_REGISTRATION( XmlTest ); diff --git a/src/libcmis/xml-utils.cxx b/src/libcmis/xml-utils.cxx index dddfafa..645fbcf 100644 --- a/src/libcmis/xml-utils.cxx +++ b/src/libcmis/xml-utils.cxx @@ -498,8 +498,12 @@ namespace libcmis sha1.get_digest( digest ); stringstream out; + // Setup writing mode. Every number must produce eight + // hexadecimal digits, including possible leading 0s, or we get + // less than 40 digits as result. + out << hex << setfill('0') << right; for ( int i = 0; i < 5; ++i ) - out << hex << digest[i]; + out << setw(8) << digest[i]; return out.str(); } -- 1.8.1.4