aboutsummaryrefslogtreecommitdiff
path: root/rsa/util.py
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2016-01-22 11:36:06 +0100
committerSybren A. Stüvel <sybren@stuvel.eu>2016-01-22 11:36:06 +0100
commitd3d10345b47c2b17922bb91059cfceea82f82338 (patch)
tree6a336d74ee41a4ba98b6b3d97f123cd0c5f4e9b7 /rsa/util.py
parent541ee468b6b33c7ae27818bbfea63df9622f9d8a (diff)
downloadrsa-d3d10345b47c2b17922bb91059cfceea82f82338.tar.gz
Big refactor to become more PEP8 compliant.
Mostly focused on docstrings (''' → """), indentation, empty lines, and superfluous parenthesis.
Diffstat (limited to 'rsa/util.py')
-rw-r--r--rsa/util.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/rsa/util.py b/rsa/util.py
index 5bbb70b..df3f6ef 100644
--- a/rsa/util.py
+++ b/rsa/util.py
@@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-'''Utility functions.'''
+"""Utility functions."""
from __future__ import with_statement, print_function
@@ -23,34 +23,35 @@ from optparse import OptionParser
import rsa.key
+
def private_to_public():
- '''Reads a private key and outputs the corresponding public key.'''
+ """Reads a private key and outputs the corresponding public key."""
# Parse the CLI options
parser = OptionParser(usage='usage: %prog [options]',
- description='Reads a private key and outputs the '
- 'corresponding public key. Both private and public keys use '
- 'the format described in PKCS#1 v1.5')
+ description='Reads a private key and outputs the '
+ 'corresponding public key. Both private and public keys use '
+ 'the format described in PKCS#1 v1.5')
parser.add_option('-i', '--input', dest='infilename', type='string',
- help='Input filename. Reads from stdin if not specified')
+ help='Input filename. Reads from stdin if not specified')
parser.add_option('-o', '--output', dest='outfilename', type='string',
- help='Output filename. Writes to stdout of not specified')
+ help='Output filename. Writes to stdout of not specified')
parser.add_option('--inform', dest='inform',
- help='key format of input - default PEM',
- choices=('PEM', 'DER'), default='PEM')
+ help='key format of input - default PEM',
+ choices=('PEM', 'DER'), default='PEM')
parser.add_option('--outform', dest='outform',
- help='key format of output - default PEM',
- choices=('PEM', 'DER'), default='PEM')
+ help='key format of output - default PEM',
+ choices=('PEM', 'DER'), default='PEM')
(cli, cli_args) = parser.parse_args(sys.argv)
# Read the input data
if cli.infilename:
print('Reading private key from %s in %s format' % \
- (cli.infilename, cli.inform), file=sys.stderr)
+ (cli.infilename, cli.inform), file=sys.stderr)
with open(cli.infilename, 'rb') as infile:
in_data = infile.read()
else:
@@ -60,7 +61,6 @@ def private_to_public():
assert type(in_data) == bytes, type(in_data)
-
# Take the public fields and create a public key
priv_key = rsa.key.PrivateKey.load_pkcs1(in_data, cli.inform)
pub_key = rsa.key.PublicKey(priv_key.n, priv_key.e)
@@ -70,12 +70,10 @@ def private_to_public():
if cli.outfilename:
print('Writing public key to %s in %s format' % \
- (cli.outfilename, cli.outform), file=sys.stderr)
+ (cli.outfilename, cli.outform), file=sys.stderr)
with open(cli.outfilename, 'wb') as outfile:
outfile.write(out_data)
else:
print('Writing public key to stdout in %s format' % cli.outform,
file=sys.stderr)
sys.stdout.write(out_data.decode('ascii'))
-
-