Changeset 265 for trunk

Show
Ignore:
Timestamp:
04/06/09 21:18:52 (3 years ago)
Author:
ocjhb
Message:

error message type

Location:
trunk/sandbox/jhb/oc2
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/sandbox/jhb/oc2/documentation.py

    r264 r265  
    443443############################################################################### 
    444444 
     445We first need to setup something to sign the requests for authorization 
     446 
    445447>>> from authorizer import Authorizer 
    446448>>> authorizer = Authorizer({}) 
    447449>>> authpub = authorizer.createKeys()  
    448450>>> mint.addAuthKey(authpub) 
     451>>> authorizer.setMKCs(mkcs) 
     452 
     453 
     454good, lets start the action 
    449455>>> clientside = protocols.TransferRequest(transport,tid,'foo',[[mkc.keyId,blind]],[]) 
    450456>>> testserver.run_once(port,mint=mint,authorizer=authorizer) 
     
    452458>>> text 
    453459u'minted' 
    454 >>> blindsign = value[0][1] 
     460>>> blindsign = value[0] 
    455461>>> blank.signature = key.unblind(secret,blindsign) 
    456462>>> coin = blank 
  • trunk/sandbox/jhb/oc2/messages.py

    r264 r265  
    5252        Field('signature',signing=False) 
    5353    ] 
     54class Error(Message): 
     55    fields = Message.fields + [ 
     56        Field('text'), 
     57        Field('data'), 
     58        Field('keyId'), 
     59        Field('signature',signing=False) 
     60    ] 
     61 
     62class TransferReject(Message): 
     63    pass 
    5464 
    5565 
  • trunk/sandbox/jhb/oc2/mint.py

    r264 r265  
    3737        return self.storage['keyids'][keyid] 
    3838 
    39     def denominationToValue(self,denomination): 
    40         return int(denomination) 
    41  
    4239 
    4340    def addAuthKey(self,key): 
     
    5451 
    5552    def handleTransferRequest(self,authorizedMessage): 
    56          
     53          
    5754        if not self.validateAuthorization(authorizedMessage): 
    5855            return ('nonvalid','') 
    5956        else:  
    6057            message = authorizedMessage.message 
    61          
    62         target = message.target 
    6358        blinds = message.blinds 
    64         coins = message.coins 
    65  
    66         amount = 0 
    67         currentversion = len(self.storage['keys']) - 1 
    68         errors = None 
    6959        result = [] 
    70         mintkeys = [] 
    71  
    7260        for keyid,blind in blinds: 
    73             error = None 
    7461            priv,pub,denomination,version = self.getMintKeyById(keyid) 
    75             mintkeys.append(priv) 
    76             if version != currentversion: 
    77                 error = 'Key not current' 
    78              
    79             if error: 
    80                 errors = True 
    81                 result.append(('error',error)) 
    82             else: 
    83                 result.append(['ok','']) 
    84      
    85             amount += self.denominationToValue(denomination) 
    86          
    87         if errors: 
    88             return ('errors',result) 
    89  
    90         else: 
    91             i = 0 
    92             for keyid,blind in blinds: 
    93                 signature = mintkeys[i].sign(blind) 
    94                 result[i][1] = signature 
    95                 i += 1 
    96                          
     62            signature = priv.sign(blind) 
     63            result.append(signature) 
     64                     
    9765        return ('minted',result) 
    9866 
  • trunk/sandbox/jhb/oc2/protocols.py

    r264 r265  
    8383    def run(self,message=None): 
    8484        if self.target and self.blinds: 
    85             type = 'mint' 
     85            requesttype = 'mint' 
    8686        elif self.target and self.coins: 
    87             type = 'redeem' 
     87            requesttype = 'redeem' 
    8888        elif self.blinds and self.coins: 
    89             type = 'exchange' 
     89            requesttype = 'exchange' 
    9090        else: 
    9191            raise 'Not a valid combination of options' 
     
    9696        message.blinds = self.blinds 
    9797        message.coins = self.coins 
    98         message.options = dict(type=type).items() 
     98        message.options = dict(type=requesttype).items() 
    9999 
    100100        response = self.transport(message) 
    101101        header = response.header 
    102102        if header == 'TransferReject': 
    103             return ('TRansferReject','') 
     103            return ('TransferReject','') 
    104104        elif header == 'TransferDelay': 
    105105            return ('TransferDelay','') 
     
    117117    def run(self,message): 
    118118        options = dict(message.options) 
    119         type = options['type'] 
    120         if type == 'mint': 
     119        requesttype = options['type'] 
     120        if requesttype == 'mint': 
    121121            authorizedMessage = self.authorizer.authorize(message) 
    122             if not authorizedMessage: 
    123                 raise 'not authorized' 
    124             text,value = self.mint.handleTransferRequest(authorizedMessage) 
    125             if text == 'minted': 
     122            if type(authorizedMessage) == messages.Error: 
     123                return messages.TransferReject() 
     124                  
     125            response  = self.mint.handleTransferRequest(authorizedMessage) 
     126            if type(response) == messages.Error: 
     127                return messages.TransferReject() 
     128 
     129            text,value = response 
     130            if value: 
    126131                answer = messages.TransferAccept() 
    127132                answer.text = text