@@ -41,15 +41,17 @@ class AbstractKey(object):
4141 def load_pkcs1 (cls , keyfile , format = 'PEM' ):
4242 r'''Loads a key in PKCS#1 DER or PEM format.
4343
44- @ param keyfile: contents of a DER- or PEM-encoded file that contains
44+ : param keyfile: contents of a DER- or PEM-encoded file that contains
4545 the public key.
46- @param format: the format of the file to load; 'PEM' or 'DER'
47- @return: a PublicKey object
46+ :param format: the format of the file to load; 'PEM' or 'DER'
47+
48+ :return: a PublicKey object
49+
4850 '''
4951
5052 methods = {
51- 'PEM' : cls .load_pkcs1_pem ,
52- 'DER' : cls .load_pkcs1_der ,
53+ 'PEM' : cls ._load_pkcs1_pem ,
54+ 'DER' : cls ._load_pkcs1_der ,
5355 }
5456
5557 if format not in methods :
@@ -63,13 +65,14 @@ def load_pkcs1(cls, keyfile, format='PEM'):
6365 def save_pkcs1 (self , format = 'PEM' ):
6466 '''Saves the public key in PKCS#1 DER or PEM format.
6567
66- @param format: the format to save; 'PEM' or 'DER'
67- @returns: the DER- or PEM-encoded public key.
68+ :param format: the format to save; 'PEM' or 'DER'
69+ :returns: the DER- or PEM-encoded public key.
70+
6871 '''
6972
7073 methods = {
71- 'PEM' : self .save_pkcs1_pem ,
72- 'DER' : self .save_pkcs1_der ,
74+ 'PEM' : self ._save_pkcs1_pem ,
75+ 'DER' : self ._save_pkcs1_der ,
7376 }
7477
7578 if format not in methods :
@@ -86,7 +89,8 @@ class PublicKey(AbstractKey):
8689 This key is also known as the 'encryption key'. It contains the 'n' and 'e'
8790 values.
8891
89- Supports attributes as well as dictionary-like access.
92+ Supports attributes as well as dictionary-like access. Attribute accesss is
93+ faster, though.
9094
9195 >>> PublicKey(5, 3)
9296 PublicKey(5, 3)
@@ -128,7 +132,7 @@ def __ne__(self, other):
128132 return not (self == other )
129133
130134 @classmethod
131- def load_pkcs1_der (cls , keyfile ):
135+ def _load_pkcs1_der (cls , keyfile ):
132136 r'''Loads a key in PKCS#1 DER format.
133137
134138 @param keyfile: contents of a DER-encoded file that contains the public
@@ -160,7 +164,7 @@ def load_pkcs1_der(cls, keyfile):
160164 as_ints = tuple (int (x ) for x in priv )
161165 return cls (* as_ints )
162166
163- def save_pkcs1_der (self ):
167+ def _save_pkcs1_der (self ):
164168 '''Saves the public key in PKCS#1 DER format.
165169
166170 @returns: the DER-encoded public key.
@@ -183,7 +187,7 @@ class AsnPubKey(univ.Sequence):
183187 return encoder .encode (asn_key )
184188
185189 @classmethod
186- def load_pkcs1_pem (cls , keyfile ):
190+ def _load_pkcs1_pem (cls , keyfile ):
187191 '''Loads a PKCS#1 PEM-encoded public key file.
188192
189193 The contents of the file before the "-----BEGIN RSA PUBLIC KEY-----" and
@@ -197,7 +201,7 @@ def load_pkcs1_pem(cls, keyfile):
197201 der = rsa .pem .load_pem (keyfile , 'RSA PUBLIC KEY' )
198202 return cls .load_pkcs1_der (der )
199203
200- def save_pkcs1_pem (self ):
204+ def _save_pkcs1_pem (self ):
201205 '''Saves a PKCS#1 PEM-encoded public key file.
202206
203207 @return: contents of a PEM-encoded file that contains the public key.
@@ -212,7 +216,8 @@ class PrivateKey(AbstractKey):
212216 This key is also known as the 'decryption key'. It contains the 'n', 'e',
213217 'd', 'p', 'q' and other values.
214218
215- Supports attributes as well as dictionary-like access.
219+ Supports attributes as well as dictionary-like access. Attribute accesss is
220+ faster, though.
216221
217222 >>> PrivateKey(3247, 65537, 833, 191, 17)
218223 PrivateKey(3247, 65537, 833, 191, 17)
@@ -290,7 +295,7 @@ def __ne__(self, other):
290295 return not (self == other )
291296
292297 @classmethod
293- def load_pkcs1_der (cls , keyfile ):
298+ def _load_pkcs1_der (cls , keyfile ):
294299 r'''Loads a key in PKCS#1 DER format.
295300
296301 @param keyfile: contents of a DER-encoded file that contains the private
@@ -334,7 +339,7 @@ def load_pkcs1_der(cls, keyfile):
334339 as_ints = tuple (int (x ) for x in priv [1 :9 ])
335340 return cls (* as_ints )
336341
337- def save_pkcs1_der (self ):
342+ def _save_pkcs1_der (self ):
338343 '''Saves the private key in PKCS#1 DER format.
339344
340345 @returns: the DER-encoded private key.
@@ -371,7 +376,7 @@ class AsnPrivKey(univ.Sequence):
371376 return encoder .encode (asn_key )
372377
373378 @classmethod
374- def load_pkcs1_pem (cls , keyfile ):
379+ def _load_pkcs1_pem (cls , keyfile ):
375380 '''Loads a PKCS#1 PEM-encoded private key file.
376381
377382 The contents of the file before the "-----BEGIN RSA PRIVATE KEY-----" and
@@ -385,7 +390,7 @@ def load_pkcs1_pem(cls, keyfile):
385390 der = rsa .pem .load_pem (keyfile , 'RSA PRIVATE KEY' )
386391 return cls .load_pkcs1_der (der )
387392
388- def save_pkcs1_pem (self ):
393+ def _save_pkcs1_pem (self ):
389394 '''Saves a PKCS#1 PEM-encoded private key file.
390395
391396 @return: contents of a PEM-encoded file that contains the private key.
@@ -535,15 +540,16 @@ def gen_keys(nbits, accurate=True):
535540def newkeys (nbits , accurate = True ):
536541 """Generates public and private keys, and returns them as (pub, priv).
537542
538- The public key is also known as the 'encryption key', and is a PublicKey
539- object. The private key is also known as the 'decryption key' and is a
540- PrivateKey object.
541-
542- @param nbits: the number of bits required to store ``n = p*q``.
543- @param accurate: when True, ``n`` will have exactly the number of bits you
544- asked for. However, this makes key generation much slower.
543+ The public key is also known as the 'encryption key', and is a
544+ :py:class:`PublicKey` object. The private key is also known as the
545+ 'decryption key' and is a :py:class:`PrivateKey` object.
546+
547+ :param nbits: the number of bits required to store ``n = p*q``.
548+ :param accurate: when True, ``n`` will have exactly the number of bits you
549+ asked for. However, this makes key generation much slower. When False,
550+ `n`` may have slightly less bits.
545551
546- @return: a tuple (PublicKey, PrivateKey)
552+ :returns: a tuple (:py:class:`rsa. PublicKey`, :py:class:`rsa. PrivateKey` )
547553
548554 """
549555
0 commit comments