Repository: pyca/cryptography

Issue:
Deprecate PublicKeyWithSerialization?
@alex and I talked about this in channel a few days ago, but is anyone aware of a situation where a public key will be opaque and unable to be serialized? If not, should we just make the PublicKey interfaces have the WithSerialization methods and potentially deprecate/remove the old interfaces?



Discussion:
I'm going to go ahead and say this should be impossible. PublicKeys must be serializable.

I agree -- I think the context of this question was whether we should get rid of WithSerialization and just have PublicKey imply it. I think the deprecation cycle and inconsistency makes this not worth it though. I'm fine with this being closed if you agree Alex.

Any reason not to add the methods to the base `PublicKey` and then make
`WithSerialization` a deprecated alias for an extended period of time?

On Sat, Jul 4, 2015 at 11:05 AM, Paul Kehrer notifications@github.com
wrote:

> I agree -- I think the context of this question was whether we should get
> rid of WithSerialization and just have PublicKey imply it. I think the
> deprecation cycle and inconsistency makes this not worth it though. I'm
> fine with this being closed if you agree Alex.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/pyca/cryptography/issues/1748#issuecomment-118518476.

## 

"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: 125F 5C67 DFE9 4084

I think I'd like "WithSerialization" to stay permanently as an alias since it is consistent with the privatekey naming, but otherwise I am happy with moving the methods to the base.

Sounds good.

On Sat, Jul 4, 2015 at 11:10 AM, Paul Kehrer notifications@github.com
wrote:

> I think I'd like "WithSerialization" to stay permanently as an alias since
> it is consistent with the privatekey naming, but otherwise I am happy with
> moving the methods to the base.
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/pyca/cryptography/issues/1748#issuecomment-118518642.

## 

"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: 125F 5C67 DFE9 4084


Resolving patch:
diff --git a/src/cryptography/hazmat/primitives/asymmetric/dsa.py b/src/cryptography/hazmat/primitives/asymmetric/dsa.py
--- a/src/cryptography/hazmat/primitives/asymmetric/dsa.py
+++ b/src/cryptography/hazmat/primitives/asymmetric/dsa.py
@@ -91,9 +91,6 @@ def verifier(self, signature, signature_algorithm):
         Returns an AsymmetricVerificationContext used for signing data.
         """
 
-
-@six.add_metaclass(abc.ABCMeta)
-class DSAPublicKeyWithSerialization(DSAPublicKey):
     @abc.abstractmethod
     def public_numbers(self):
         """
@@ -107,6 +104,9 @@ def public_bytes(self, encoding, format):
         """
 
 
+DSAPublicKeyWithSerialization = DSAPublicKey
+
+
 def generate_parameters(key_size, backend):
     return backend.generate_dsa_parameters(key_size)
 
diff --git a/src/cryptography/hazmat/primitives/asymmetric/ec.py b/src/cryptography/hazmat/primitives/asymmetric/ec.py
--- a/src/cryptography/hazmat/primitives/asymmetric/ec.py
+++ b/src/cryptography/hazmat/primitives/asymmetric/ec.py
@@ -85,9 +85,6 @@ def curve(self):
         The EllipticCurve that this key is on.
         """
 
-
-@six.add_metaclass(abc.ABCMeta)
-class EllipticCurvePublicKeyWithSerialization(EllipticCurvePublicKey):
     @abc.abstractmethod
     def public_numbers(self):
         """
@@ -101,6 +98,9 @@ def public_bytes(self, encoding, format):
         """
 
 
+EllipticCurvePublicKeyWithSerialization = EllipticCurvePublicKey
+
+
 @utils.register_interface(EllipticCurve)
 class SECT571R1(object):
     name = "sect571r1"
diff --git a/src/cryptography/hazmat/primitives/asymmetric/rsa.py b/src/cryptography/hazmat/primitives/asymmetric/rsa.py
--- a/src/cryptography/hazmat/primitives/asymmetric/rsa.py
+++ b/src/cryptography/hazmat/primitives/asymmetric/rsa.py
@@ -76,9 +76,6 @@ def key_size(self):
         The bit length of the public modulus.
         """
 
-
-@six.add_metaclass(abc.ABCMeta)
-class RSAPublicKeyWithSerialization(RSAPublicKey):
     @abc.abstractmethod
     def public_numbers(self):
         """
@@ -92,6 +89,9 @@ def public_bytes(self, encoding, format):
         """
 
 
+RSAPublicKeyWithSerialization = RSAPublicKey
+
+
 def generate_private_key(public_exponent, key_size, backend):
     if not isinstance(backend, RSABackend):
         raise UnsupportedAlgorithm(


Test patch: