*: Run update-copyright.py
[pyassuan.git] / bin / pinentry.py
index d2e57e0170adef28c984a080a150cadf717569dd..9a7380a7b4e614e7fd29647f77868ad0831108a9 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 #
-# Copyright (C) 2012 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2012-2017 W. Trevor King <wking@tremily.us>
 #
 # This file is part of pyassuan.
 #
@@ -218,9 +218,12 @@ class PinEntry (_server.AssuanServer):
         # drop trailing newline
         return self.connection['from_user'].readline()[:-1]
 
-    def _prompt(self, prompt='?', add_colon=True):
+    def _prompt(self, prompt='?', error=None, add_colon=True):
         if add_colon:
             prompt += ':'
+        if error:
+            self.connection['to_user'].write(error)
+            self.connection['to_user'].write('\n')
         self.connection['to_user'].write(prompt)
         self.connection['to_user'].write(' ')
         self.connection['to_user'].flush()
@@ -241,6 +244,9 @@ class PinEntry (_server.AssuanServer):
         self.strings['key info'] = arg
         yield _common.Response('OK')
 
+    def _handle_CLEARPASSPHRASE(self, arg):
+        yield _common.Response('OK')
+
     def _handle_SETDESC(self, arg):
         self.strings['description'] = arg
         yield _common.Response('OK')
@@ -314,7 +320,10 @@ class PinEntry (_server.AssuanServer):
                 self._write('key: {}'.format(self.strings['key info']))
             if 'qualitybar' in self.strings:
                 self._write(self.strings['qualitybar'])
-            pin = self._prompt(self.strings['prompt'], add_colon=False)
+            pin = self._prompt(
+                prompt=self.strings['prompt'],
+                error=self.strings.get('error'),
+                add_colon=False)
         finally:
             self._disconnect()
         yield _common.Response('D', pin.encode('ascii'))