aboutsummaryrefslogtreecommitdiff
path: root/libbutl/sha256.mxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-01-19 00:02:21 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-02-08 20:49:08 +0300
commit4d30878d8efb86fd110c3693024db5da7aceb776 (patch)
treeb46ac328b499989ce27e48ca48bcc16f9f42d882 /libbutl/sha256.mxx
parenta12216dd1ed9582fc96805189caadc2b733a4e70 (diff)
Add abbreviated_string() to sha* classes
Diffstat (limited to 'libbutl/sha256.mxx')
-rw-r--r--libbutl/sha256.mxx14
1 files changed, 10 insertions, 4 deletions
diff --git a/libbutl/sha256.mxx b/libbutl/sha256.mxx
index 23a116a..1584be8 100644
--- a/libbutl/sha256.mxx
+++ b/libbutl/sha256.mxx
@@ -111,6 +111,12 @@ LIBBUTL_MODEXPORT namespace butl
const char*
string () const;
+ std::string
+ abbreviated_string (std::size_t n) const
+ {
+ return std::string (string (), n < 64 ? n : 64);
+ }
+
private:
struct context // Note: identical to SHA256_CTX.
{
@@ -137,10 +143,10 @@ LIBBUTL_MODEXPORT namespace butl
LIBBUTL_SYMEXPORT std::string
sha256_to_fingerprint (const std::string&);
- // Convert a fingerprint (32 colon-separated hex digit pairs) to the SHA256
- // string representation (64 lower case hex digits). Throw invalid_argument
- // if the argument is not a valid fingerprint.
+ // Convert a fingerprint (32 colon-separated hex digit pairs) to the possibly
+ // abbreviated SHA256 string representation (up to 64 lower case hex digits).
+ // Throw invalid_argument if the first argument is not a valid fingerprint.
//
LIBBUTL_SYMEXPORT std::string
- fingerprint_to_sha256 (const std::string&);
+ fingerprint_to_sha256 (const std::string&, std::size_t = 64);
}