parsav  Diff

Differences From Artifact [e8a79576f0]:

To Artifact [78b2aad470]:


    22     22   		[lib.mem.ptr(uint8)] {ptr = [&uint8](secret.ptr), ct = secret.ct},
    23     23   		[lib.mem.ptr( int8)] {ptr = out, ct = len},
    24     24   	&hash[0])
    25     25   	ptr = ptr + lib.math.shorthand.gen(lib.math.truncate64(hash, [hash.type.N]), ptr)
    26     26   	return ptr - out
    27     27   end
    28     28   
    29         -terra m.cookie_interpret(secret: lib.mem.ptr(int8), c: lib.mem.ptr(int8), now: uint64): uint64 -- returns either 0 or a valid authid
           29  +terra m.cookie_interpret(secret: lib.mem.ptr(int8), c: lib.mem.ptr(int8), now: uint64) -- returns either 0,0 or a valid {authid, timepoint}
    30     30   	var authid_sz = lib.str.cspan(c.ptr, lib.str.lit '.', c.ct)
    31         -	if authid_sz == 0 then return 0 end
    32         -	if authid_sz + 1 > c.ct then return 0 end
           31  +	if authid_sz == 0 then return 0,0 end
           32  +	if authid_sz + 1 > c.ct then return 0,0 end
    33     33   	var time_sz = lib.str.cspan(c.ptr+authid_sz+1, lib.str.lit '.', c.ct - (authid_sz+1))
    34         -	if time_sz == 0 then return 0 end
    35         -	if (authid_sz + time_sz + 2) > c.ct then return 0 end
           34  +	if time_sz == 0 then return 0,0 end
           35  +	if (authid_sz + time_sz + 2) > c.ct then return 0,0 end
    36     36   	var hash_sz = c.ct - (authid_sz + time_sz + 2)
    37     37   
    38     38   	var knownhash: uint8[lib.crypt.algsz.sha256]
    39     39   	lib.crypt.hmac(lib.crypt.alg.sha256,
    40     40   		[lib.mem.ptr(uint8)] {ptr = [&uint8](secret.ptr), ct = secret.ct},
    41     41   		[lib.mem.ptr( int8)] {ptr = c.ptr, ct = c.ct - hash_sz},
    42     42   	&knownhash[0])
    43     43   
    44     44   	var authid, authok = lib.math.shorthand.parse(c.ptr, authid_sz)
    45     45   	var time, timeok = lib.math.shorthand.parse(c.ptr + authid_sz + 1, time_sz)
    46     46   	var hash, hashok = lib.math.shorthand.parse(c.ptr + c.ct - hash_sz, hash_sz)
    47         -	if not (timeok and authok and hashok) then return 0 end
    48         -	if lib.math.truncate64(knownhash, [knownhash.type.N]) ~= hash then return 0 end
    49         -	if now - time > m.maxage then return 0 end
           47  +	if not (timeok and authok and hashok) then return 0,0 end
           48  +	if lib.math.truncate64(knownhash, [knownhash.type.N]) ~= hash then return 0,0 end
           49  +	if now - time > m.maxage then return 0,0 end
    50     50   
    51         -	return authid
           51  +	return authid, time
    52     52   end
    53     53   
    54     54   return m