diff options
Diffstat (limited to 'src/mongo/shell/shell_utils.cpp')
-rw-r--r-- | src/mongo/shell/shell_utils.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/mongo/shell/shell_utils.cpp b/src/mongo/shell/shell_utils.cpp index 4c1d70f6f03..d0189a75432 100644 --- a/src/mongo/shell/shell_utils.cpp +++ b/src/mongo/shell/shell_utils.cpp @@ -183,6 +183,33 @@ BSONObj validateIndexKey(const BSONObj& a, void* data) { return BSON("" << BSON("ok" << true)); } +BSONObj computeSHA256Block(const BSONObj& a, void* data) { + std::vector<ConstDataRange> blocks; + + auto ele = a[0]; + + BSONObjBuilder bob; + switch (ele.type()) { + case BinData: { + int len; + const char* ptr = ele.binData(len); + SHA256Block::computeHash({ConstDataRange(ptr, len)}).appendAsBinData(bob, ""_sd); + + break; + } + case String: { + auto str = ele.valueStringData(); + SHA256Block::computeHash({ConstDataRange(str.rawData(), str.size())}) + .appendAsBinData(bob, ""_sd); + break; + } + default: + uasserted(ErrorCodes::BadValue, "Can only computeSHA256Block of strings and bindata"); + } + + return bob.obj(); +} + BSONObj replMonitorStats(const BSONObj& a, void* data) { uassert(17134, "replMonitorStats requires a single string argument (the ReplSet name)", @@ -226,6 +253,7 @@ void installShellUtils(Scope& scope) { scope.injectNative("getBuildInfo", getBuildInfo); scope.injectNative("isKeyTooLarge", isKeyTooLarge); scope.injectNative("validateIndexKey", validateIndexKey); + scope.injectNative("computeSHA256Block", computeSHA256Block); #ifndef MONGO_SAFE_SHELL // can't launch programs |