Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) 2015-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5"""Test share/rpcauth/rpcauth.py6"""7import hmac8import importlib9import os10import re11import sys13from test_framework.test_framework import BitcoinTestFramework14from test_framework.util import assert_equal17class RpcAuthTest(BitcoinTestFramework):18def set_test_params(self):19self.num_nodes = 0 # No node/datadir needed21def setup_network(self):22pass24def setUp(self):25sys.path.insert(0, os.path.dirname(self.config["environment"]["RPCAUTH"]))26self.rpcauth = importlib.import_module('rpcauth')28def run_test(self):29self.setUp()31self.test_generate_salt()32self.test_generate_password()33self.test_check_password_hmac()35def test_generate_salt(self):36for i in range(16, 32 + 1):37assert_equal(len(self.rpcauth.generate_salt(i)), i * 2)39def test_generate_password(self):40"""Test that generated passwords only consist of urlsafe characters."""41r = re.compile(r"[0-9a-zA-Z_-]*")42password = self.rpcauth.generate_password()43assert r.fullmatch(password)45def test_check_password_hmac(self):46salt = self.rpcauth.generate_salt(16)47password = self.rpcauth.generate_password()48password_hmac = self.rpcauth.password_to_hmac(salt, password)50m = hmac.new(salt.encode('utf-8'), password.encode('utf-8'), 'SHA256')51expected_password_hmac = m.hexdigest()53assert_equal(expected_password_hmac, password_hmac)56if __name__ == '__main__':57RpcAuthTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.