@@ -13,6 +13,7 @@ extern "C" {
1313
1414}
1515
16+ #include < array>
1617#include < vector>
1718#include < algorithm>
1819#include < cctype>
@@ -26,34 +27,34 @@ namespace ur {
2627#define SHA256_LEN 32
2728
2829ByteVector sha256 (const ByteVector &buf) {
29- uint8_t digest[SHA256_LEN] ;
30+ array< uint8_t ,SHA256_LEN> digest;
3031 mbedtls_sha256_context ctx;
3132 mbedtls_sha256_init (&ctx);
3233 mbedtls_sha256_starts (&ctx, 0 );
33- mbedtls_sha256_update (&ctx, & buf[ 0 ] , buf.size ());
34- mbedtls_sha256_finish (&ctx, digest);
34+ mbedtls_sha256_update (&ctx, buf. data () , buf.size ());
35+ mbedtls_sha256_finish (&ctx, digest. data () );
3536 mbedtls_sha256_free (&ctx);
3637
37- return ByteVector ( digest, digest + SHA256_LEN) ;
38+ return { digest. begin () , digest. end ()} ;
3839}
3940
4041ByteVector crc32_bytes (const ByteVector &buf) {
41- uint32_t checksum = ur_crc32n (& buf[ 0 ] , buf.size ());
42- auto cbegin = (uint8_t *)&checksum;
43- auto cend = cbegin + sizeof (uint32_t );
44- return ByteVector ( cbegin, cend) ;
42+ uint32_t checksum = ur_crc32n (buf. data () , buf.size ());
43+ auto * cbegin = (uint8_t *)&checksum;
44+ auto * cend = cbegin + sizeof (uint32_t );
45+ return { cbegin, cend} ;
4546}
4647
4748uint32_t crc32_int (const ByteVector &buf) {
48- return ur_crc32 (& buf[ 0 ] , buf.size ());
49+ return ur_crc32 (buf. data () , buf.size ());
4950}
5051
5152ByteVector string_to_bytes (const string& s) {
52- return ByteVector ( s.begin (), s.end ()) ;
53+ return { s.begin (), s.end ()} ;
5354}
5455
5556string data_to_hex (const ByteVector& in) {
56- auto hex = " 0123456789abcdef" ;
57+ const string hex = " 0123456789abcdef" ;
5758 string result;
5859 for (auto c: in) {
5960 result.append (1 , hex[(c >> 4 ) & 0xF ]);
@@ -121,7 +122,7 @@ StringVector split(const string& s, char separator) {
121122 }
122123 }
123124
124- if (buf != " " ) {
125+ if (!buf. empty () ) {
125126 result.push_back (buf);
126127 }
127128
@@ -142,12 +143,12 @@ string take_first(const string &s, size_t count) {
142143 auto first = s.begin ();
143144 auto c = min (s.size (), count);
144145 auto last = first + c;
145- return string ( first, last) ;
146+ return { first, last} ;
146147}
147148
148149string drop_first (const string& s, size_t count) {
149150 if (count >= s.length ()) { return " " ; }
150- return string ( s.begin () + count, s.end ()) ;
151+ return { s.begin () + count, s.end ()} ;
151152}
152153
153154void xor_into (ByteVector& target, const ByteVector& source) {
0 commit comments