diff --git a/barbican/plugin/interface/secret_store.py b/barbican/plugin/interface/secret_store.py index 7de0af0f9..5b7a5153d 100644 --- a/barbican/plugin/interface/secret_store.py +++ b/barbican/plugin/interface/secret_store.py @@ -190,7 +190,7 @@ class KeyAlgorithm(object): SYMMETRIC_ALGORITHMS = [AES, DES, DESEDE] def get_secret_type(self, alg): - if alg in self.SYMMETRIC_ALGORITHMS: + if str(alg).lower() in self.SYMMETRIC_ALGORITHMS: return SecretType.SYMMETRIC else: # TODO(kaitlin-farr) add asymmetric once it's supported return None diff --git a/barbican/plugin/store_crypto.py b/barbican/plugin/store_crypto.py index 460e2dbf3..12b766bd9 100644 --- a/barbican/plugin/store_crypto.py +++ b/barbican/plugin/store_crypto.py @@ -167,7 +167,8 @@ class StoreCryptoAdapterPlugin(sstore.SecretStoreBase): Specifies whether the plugin supports key generation with the given key_spec. """ - return key_spec and sstore.KeyAlgorithm.supports(key_spec.alg.lower()) + return (key_spec and + sstore.KeyAlgorithm().get_secret_type(key_spec.alg)) def store_secret_supports(self, key_spec): """Key storage supported? diff --git a/barbican/tests/plugin/test_store_crypto.py b/barbican/tests/plugin/test_store_crypto.py new file mode 100644 index 000000000..e0608961b --- /dev/null +++ b/barbican/tests/plugin/test_store_crypto.py @@ -0,0 +1,39 @@ +# Copyright (c) 2014 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from barbican.plugin.interface import secret_store +from barbican.plugin import store_crypto +import testtools + + +class WhenStoreCryptoAdapterPlugin(testtools.TestCase): + + def setUp(self): + super(WhenStoreCryptoAdapterPlugin, self).setUp() + self.store_crypto = store_crypto.StoreCryptoAdapterPlugin() + + def tearDown(self): + super(WhenStoreCryptoAdapterPlugin, self).tearDown() + + def test_generate_supports(self): + """test generate_supports.""" + # key_spec should not be None + self.assertFalse(self.store_crypto.generate_supports(None)) + self.key_spec = secret_store.KeySpec('AES', 64, 'CBC') + self.assertEqual(secret_store.SecretType.SYMMETRIC, + self.store_crypto.generate_supports(self.key_spec)) + self.key_spec = secret_store.KeySpec('aes', 64, 'CBC') + self.assertEqual(secret_store.SecretType.SYMMETRIC, + self.store_crypto.generate_supports(self.key_spec))