summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. St?vel <sybren@stuvel.eu>2014-02-22 11:12:09 +0100
committerSybren A. St?vel <sybren@stuvel.eu>2014-02-22 11:12:09 +0100
commit4cf0b24390e699b5b36976f68522e9757e414a05 (patch)
tree284fa30af6b8eb56cf44122485115f0b74c6f0f7
parentb31dadeb267b7f08c3aa5eed717bf9a5461d90b5 (diff)
downloadrsa-4cf0b24390e699b5b36976f68522e9757e414a05.tar.gz
Fixed compatibilty of pyrsa-priv2pub with Python 3
-rw-r--r--rsa/util.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/rsa/util.py b/rsa/util.py
index 307bda5..5bbb70b 100644
--- a/rsa/util.py
+++ b/rsa/util.py
@@ -16,7 +16,7 @@
'''Utility functions.'''
-from __future__ import with_statement
+from __future__ import with_statement, print_function
import sys
from optparse import OptionParser
@@ -49,14 +49,16 @@ def private_to_public():
# Read the input data
if cli.infilename:
- print >>sys.stderr, 'Reading private key from %s in %s format' % \
- (cli.infilename, cli.inform)
- with open(cli.infilename) as infile:
+ print('Reading private key from %s in %s format' % \
+ (cli.infilename, cli.inform), file=sys.stderr)
+ with open(cli.infilename, 'rb') as infile:
in_data = infile.read()
else:
- print >>sys.stderr, 'Reading private key from stdin in %s format' % \
- cli.inform
- in_data = sys.stdin.read()
+ print('Reading private key from stdin in %s format' % cli.inform,
+ file=sys.stderr)
+ in_data = sys.stdin.read().encode('ascii')
+
+ assert type(in_data) == bytes, type(in_data)
# Take the public fields and create a public key
@@ -67,13 +69,13 @@ def private_to_public():
out_data = pub_key.save_pkcs1(cli.outform)
if cli.outfilename:
- print >>sys.stderr, 'Writing public key to %s in %s format' % \
- (cli.outfilename, cli.outform)
- with open(cli.outfilename, 'w') as outfile:
+ print('Writing public key to %s in %s format' % \
+ (cli.outfilename, cli.outform), file=sys.stderr)
+ with open(cli.outfilename, 'wb') as outfile:
outfile.write(out_data)
else:
- print >>sys.stderr, 'Writing public key to stdout in %s format' % \
- cli.outform
- sys.stdout.write(out_data)
+ print('Writing public key to stdout in %s format' % cli.outform,
+ file=sys.stderr)
+ sys.stdout.write(out_data.decode('ascii'))