+###--------------------------------------------------------------------------
+### Commands: check
+
+def check_key(k):
+ now = T.time()
+ thresh = int(conf['kx-warn-days']) * 86400
+ if k.exptime == C.KEXP_FOREVER: return None
+ elif k.exptime == C.KEXP_EXPIRE: left = -1
+ else: left = k.exptime - now
+ if left < 0:
+ return "key `%s' HAS EXPIRED" % k.tag
+ elif left < thresh:
+ if left >= 86400: n, u, uu = left // 86400, 'day', 'days'
+ else: n, u, uu = left // 3600, 'hour', 'hours'
+ return "key `%s' EXPIRES in %d %s" % (k.tag, n, n == 1 and u or uu)
+ else:
+ return None
+
+def cmd_check(args):
+ if OS.path.exists('keyring.pub'):
+ for k in C.KeyFile('keyring.pub').itervalues():
+ whinge = check_key(k)
+ if whinge is not None: print whinge
+ if OS.path.exists('master'):
+ whinges = []
+ for k in C.KeyFile('master').itervalues():
+ whinge = check_key(k)
+ if whinge is None: break
+ whinges.append(whinge)
+ else:
+ for whinge in whinges: print whinge
+
+###--------------------------------------------------------------------------
+### Commands: mtu
+
+def mac_tagsz():
+ macname = conf['mac']
+ index = macname.rindex('/')
+ if index == -1: tagsz = C.gcmacs[macname].tagsz
+ else: tagsz = int(macname[index + 1:])/8
+ return tagsz
+
+def cmd_mtu(args):
+ mtu, = (lambda mtu = '1500': (mtu,))(*args)
+ mtu = int(mtu)
+
+ mtu -= 20 # Minimum IP header
+ mtu -= 8 # UDP header
+ mtu -= 1 # TrIPE packet type octet
+
+ bulk = conf['bulk']
+
+ if bulk == 'v0':
+ blksz = C.gcciphers[conf['cipher']].blksz
+ mtu -= mac_tagsz() # MAC tag
+ mtu -= 4 # Sequence number
+ mtu -= blksz # Initialization vector
+
+ elif bulk == 'iiv':
+ mtu -= mac_tagsz() # MAC tag
+ mtu -= 4 # Sequence number
+
+ elif bulk == 'naclbox':
+ mtu -= 16 # MAC tag
+ mtu -= 4 # Sequence number
+
+ else:
+ die("Unknown bulk transform `%s'" % bulk)
+
+ print mtu
+
+###--------------------------------------------------------------------------
+### Main driver.