Mercurial > hg > marc_php
diff marcus.php @ 4:c642254dc9ee draft default tip
Fixed transfer chain generation and construction of empty updates, some small improvements in tools
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sat, 22 Nov 2014 18:18:52 +0100 |
parents | 5c8c4fa95803 |
children |
line wrap: on
line diff
--- a/marcus.php Mon Nov 17 01:19:05 2014 +0100 +++ b/marcus.php Sat Nov 22 18:18:52 2014 +0100 @@ -68,16 +68,13 @@ case 'CREATE': $key = array('store' => TRUE); $key['pk'] = nacl_crypto_sign_ed25519_keypair($key['sk'], randombytes(32)); - $dbchanged = TRUE; echo 'Created public key '.bin2hex($key['pk'])."\n"; break; case 'FORGET': $key['store'] = FALSE; - $dbchanged = TRUE; break; case 'STORE': $key['store'] = TRUE; - $dbchanged = TRUE; break; case 'USE': $key = array('store' => FALSE, 'pk' => $resource['key']); @@ -86,7 +83,6 @@ case 'IMPORT': $key = array('store' => FALSE); $key['pk'] = nacl_crypto_sign_ed25519_keypair($key['sk'], hex2bin($argv[$argi++])); - $dbchanged = TRUE; break; case 'UNLOCK': if (!isset($key['locked'])) throw new Exception('The key is not locked'); @@ -221,10 +217,16 @@ case 'SELECT': if ($reschanged) echo "Warning: selected resource has not been updated.\n"; $reschanged = FALSE; - $label = argtolabel($argv, $argi); - $resource = $database->GetResource($label); - if (!$resource) echo "Warning: resource ".labeltoname($label)." does not exist.\n"; - else $resource = $resource->ToArray(); + if (strcasecmp($argv[$argi], 'TRANSFERCHAIN') == 0) { + $resource = MARCUpdate::Decode($resource['transferchain']); + if (!$resource) echo "Warning: failed to decode chained transfer data.\n"; + $argi++; + } else { + $label = argtolabel($argv, $argi); + $resource = $database->GetResource($label); + if (!$resource) echo "Warning: resource ".labeltoname($label)." does not exist.\n"; + } + if ($resource) $resource = $resource->ToArray(); break; case 'HELP': print_help(); @@ -270,7 +272,7 @@ if (preg_match('_^[0-9]{1-3}\.[0-9]{1-3}\.[0-9]{1-3}\.[0-9]{1-3}/[0-9]{1-2}$_', $t)) return ipnettolabel($t); if (preg_match('_^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})\z/[0-9]{1-3}_i', $t)) return ipnettolabel($t); if (preg_match('/^[a-f0-9]{64}$/i', $t)) return chr(0).hex2bin($t); - if (preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/i', $t)) return chr(4).strtolower(trim($t, '.')); + if (preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z0-9]{2,6}$/i', $t)) return chr(4).strtolower(trim($t, '.')); throw new Exception('Could not detect label type for '.$t); } } @@ -342,6 +344,7 @@ select [identifier] - select resource given by identifier select currentkey - select key resource for current key pair select resourcekey - select key resource for the key that signed the currently selected resource +select transferchain - extract the chained transfer data from the currently selected resource select label [identifier] - select resource by hexadecimal label select key [publickey] - select key resource (hexadecimal) select ip|ip4|ipv4 [ipv4network] - select resource for IPv4 network