diff --git a/activesupport/lib/active_support/core_ext/digest/uuid.rb b/activesupport/lib/active_support/core_ext/digest/uuid.rb index 906bc9608f..0f06a97980 100644 --- a/activesupport/lib/active_support/core_ext/digest/uuid.rb +++ b/activesupport/lib/active_support/core_ext/digest/uuid.rb @@ -53,6 +53,12 @@ def self.uuid_v4 SecureRandom.uuid end + # Returns the nil UUID. This is a special form of UUID that is specified to + # have all 128 bits set to zero. + def self.nil_uuid + "00000000-0000-0000-0000-000000000000" + end + def self.pack_uuid_namespace(namespace) if [DNS_NAMESPACE, OID_NAMESPACE, URL_NAMESPACE, X500_NAMESPACE].include?(namespace) namespace diff --git a/activesupport/test/core_ext/digest/uuid_test.rb b/activesupport/test/core_ext/digest/uuid_test.rb index db8d344972..4811dfa90c 100644 --- a/activesupport/test/core_ext/digest/uuid_test.rb +++ b/activesupport/test/core_ext/digest/uuid_test.rb @@ -55,6 +55,10 @@ def test_v5_uuids_with_rfc4122_namespaced_uuids_enabled end end + def test_nil_uuid + assert_equal "00000000-0000-0000-0000-000000000000", Digest::UUID.nil_uuid + end + def test_invalid_hash_class assert_raise ArgumentError do Digest::UUID.uuid_from_hash(OpenSSL::Digest::SHA256, Digest::UUID::OID_NAMESPACE, "1.2.3")