summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2016-02-25 14:21:05 -0800
committerJay Mundrawala <jdmundrawala@gmail.com>2016-02-25 14:21:05 -0800
commit84c19d769ea46b87cac6e57f12b4eb6251abc8b0 (patch)
treeee61c8af680c83ba7573078f99dfdd25c8a42586
parent5361b3c9a07fb45cb04f0d05eb366c6b4d323680 (diff)
downloadchef-84c19d769ea46b87cac6e57f12b4eb6251abc8b0.tar.gz
Refactor fips mixin
This will allow for usage in the tests
-rw-r--r--lib/chef/mixin/fips.rb22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/chef/mixin/fips.rb b/lib/chef/mixin/fips.rb
index 82e87da32b..54ae526867 100644
--- a/lib/chef/mixin/fips.rb
+++ b/lib/chef/mixin/fips.rb
@@ -27,20 +27,26 @@ class Chef
# with a working MD5 implementation.
# @api private
def with_fips_md5_exception
- if Chef::Config[:fips]
- Digest.const_set("MD5", Digest::MD5_)
- OpenSSL::Digest.const_set("MD5", Digest::MD5_)
- end
+ allow_md5 if Chef::Config[:fips]
begin
yield
ensure
- if Chef::Config[:fips]
- Digest.send(:remove_const, "MD5")
- OpenSSL::Digest.send(:remove_const, "MD5")
- end
+ disallow_md5 if Chef::Config[:fips]
end
end
+
+ # @api private
+ def allow_md5
+ Digest.const_set("MD5", Digest::MD5_)
+ OpenSSL::Digest.const_set("MD5", Digest::MD5_)
+ end
+
+ # @api private
+ def disallow_md5
+ Digest.send(:remove_const, "MD5")
+ OpenSSL::Digest.send(:remove_const, "MD5")
+ end
end
end
end