Commit 043fe297 by Scott Duckworth

rename SSHKeyFormatError to PublicKeyParseError

parent 3550b54a
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django_sshkey.util import SSHKeyFormatError, pubkey_parse from django_sshkey.util import PublicKeyParseError, pubkey_parse
class UserKey(models.Model): class UserKey(models.Model):
user = models.ForeignKey(User, db_index=True) user = models.ForeignKey(User, db_index=True)
...@@ -55,7 +55,7 @@ class UserKey(models.Model): ...@@ -55,7 +55,7 @@ class UserKey(models.Model):
def clean(self): def clean(self):
try: try:
pubkey = pubkey_parse(self.key) pubkey = pubkey_parse(self.key)
except SSHKeyFormatError as e: except PublicKeyParseError as e:
raise ValidationError(str(e)) raise ValidationError(str(e))
self.key = pubkey.format_openssh() self.key = pubkey.format_openssh()
self.fingerprint = pubkey.fingerprint() self.fingerprint = pubkey.fingerprint()
......
...@@ -52,7 +52,7 @@ def wrap(text, width, wrap_end=None): ...@@ -52,7 +52,7 @@ def wrap(text, width, wrap_end=None):
n = m n = m
return t return t
class SSHKeyFormatError(Exception): class PublicKeyParseError(Exception):
def __init__(self, text): def __init__(self, text):
self.text = text self.text = text
...@@ -90,16 +90,16 @@ class PublicKey(object): ...@@ -90,16 +90,16 @@ class PublicKey(object):
def pubkey_parse_openssh(text): def pubkey_parse_openssh(text):
fields = text.split(None, 2) fields = text.split(None, 2)
if len(fields) < 2: if len(fields) < 2:
raise SSHKeyFormatError(text) raise PublicKeyParseError(text)
try: try:
if len(fields) == 2: if len(fields) == 2:
key = PublicKey(fields[1]) key = PublicKey(fields[1])
else: else:
key = PublicKey(fields[1], fields[2]) key = PublicKey(fields[1], fields[2])
except TypeError: except TypeError:
raise SSHKeyFormatError(text) raise PublicKeyParseError(text)
if fields[0] != key.algorithm: if fields[0] != key.algorithm:
raise SSHKeyFormatError(text) raise PublicKeyParseError(text)
return key return key
def pubkey_parse_rfc4716(text): def pubkey_parse_rfc4716(text):
...@@ -108,7 +108,7 @@ def pubkey_parse_rfc4716(text): ...@@ -108,7 +108,7 @@ def pubkey_parse_rfc4716(text):
lines[0] == '---- BEGIN SSH2 PUBLIC KEY ----' lines[0] == '---- BEGIN SSH2 PUBLIC KEY ----'
and lines[-1] == '---- END SSH2 PUBLIC KEY ----' and lines[-1] == '---- END SSH2 PUBLIC KEY ----'
): ):
raise SSHKeyFormatError(text) raise PublicKeyParseError(text)
lines = lines[1:-1] lines = lines[1:-1]
b64key = '' b64key = ''
headers = {} headers = {}
...@@ -127,7 +127,7 @@ def pubkey_parse_rfc4716(text): ...@@ -127,7 +127,7 @@ def pubkey_parse_rfc4716(text):
try: try:
return PublicKey(b64key, comment) return PublicKey(b64key, comment)
except TypeError: except TypeError:
raise SSHKeyFormatError(text) raise PublicKeyParseError(text)
def pubkey_parse(text): def pubkey_parse(text):
lines = text.splitlines() lines = text.splitlines()
...@@ -138,7 +138,7 @@ def pubkey_parse(text): ...@@ -138,7 +138,7 @@ def pubkey_parse(text):
if lines[0] == '---- BEGIN SSH2 PUBLIC KEY ----': if lines[0] == '---- BEGIN SSH2 PUBLIC KEY ----':
return pubkey_parse_rfc4716(text) return pubkey_parse_rfc4716(text)
raise SSHKeyFormatError(text) raise PublicKeyParseError(text)
def lookup_all(url): def lookup_all(url):
import urllib import urllib
...@@ -190,7 +190,7 @@ def lookup_by_fingerprint_main(): ...@@ -190,7 +190,7 @@ def lookup_by_fingerprint_main():
sys.exit(1) sys.exit(1)
try: try:
pubkey = pubkey_parse(key) pubkey = pubkey_parse(key)
except SSHKeyFormatError as e: except PublicKeyParseError as e:
sys.stderr.write("Error: " + str(e)) sys.stderr.write("Error: " + str(e))
sys.exit(1) sys.exit(1)
fingerprint = pubkey.fingerprint() fingerprint = pubkey.fingerprint()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment