883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
66 lines
2.6 KiB
Python
66 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Frozen original70334 keyring update vectors through the actual codec ABI.
|
|
|
|
Explicit GW_TEST_CODEC_PATH selects the candidate; there is no installed-client
|
|
or implicit old-codec fallback. --vectors-out writes portable input/output hex
|
|
for the native Windows runner without loading any library.
|
|
"""
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
|
|
P=struct.pack
|
|
SELF,REALM,MAP=42,70,0
|
|
FIRST=624+24
|
|
|
|
def packed(low,high):
|
|
raw=P('<QQ',low,high)
|
|
return P('<H',sum(1<<i for i,b in enumerate(raw)if b))+bytes(b for b in raw if b)
|
|
|
|
def bits(value):
|
|
value+='0'*((-len(value))%8)
|
|
return int(value,2).to_bytes(len(value)//8,'big')
|
|
|
|
def vector(slots,clear=False):
|
|
fields={}
|
|
for i in slots:
|
|
guid=0 if clear else (0x4000<<48)|(1000+i)
|
|
fields[FIRST+2*i]=guid&0xffffffff
|
|
fields[FIRST+2*i+1]=guid>>32
|
|
data=P('<QHII',SELF,REALM,MAP,1)+P('<QBBH',SELF,4,0,len(fields))
|
|
data+=b''.join(P('<HI',i,v)for i,v in sorted(fields.items()))
|
|
blocks=[0]*14
|
|
blocks[168//32]|=1<<(168%32)
|
|
for i in slots:blocks[(281+i)//32]|=1<<((281+i)%32)
|
|
mask=sum(1<<i for i,v in enumerate(blocks)if v)
|
|
native_mask=bits(f'{mask:014b}'+''.join(f'{v:032b}'for v in blocks if v))
|
|
guids=b''.join(packed(0,0)if clear else packed(1000+i,3<<58)for i in sorted(slots))
|
|
values=bytes([1,0,3])+P('<I',1<<7)+native_mask+guids
|
|
block=b'\0'+packed(SELF,(2<<58)|(REALM<<42))+P('<I',len(values))+values
|
|
expected=P('<HIBI',MAP,1,128,len(block))+block
|
|
return dict(mode=25,input_hex=data.hex(),expected_hex=expected.hex(),slots=slots,clear=clear)
|
|
|
|
def vectors():
|
|
return [vector([i])for i in range(32)]+[
|
|
vector([0,31]),vector(list(range(32))),
|
|
vector([0,31],True),vector(list(range(32)),True)]
|
|
|
|
def main():
|
|
parser=argparse.ArgumentParser();parser.add_argument('--vectors-out',type=Path);args=parser.parse_args()
|
|
cases=vectors()
|
|
if args.vectors_out:
|
|
args.vectors_out.write_text(json.dumps(dict(schema=1,kind='original70334-source-keyring-codec-goldens',vectors=cases),indent=2)+'\n')
|
|
print('Wrote36 portable keyring native-codec vectors');return
|
|
selected=os.environ.get('GW_TEST_CODEC_PATH')
|
|
if not selected or not Path(selected).is_file():sys.exit(77)
|
|
from native_codec_driver import load,serialize
|
|
library=load()
|
|
for row in cases:
|
|
assert serialize(library,row['mode'],bytes.fromhex(row['input_hex'])).hex()==row['expected_hex'],row
|
|
print('Actual codec32 single slots + first/last/all32 update/clear exact native mask/GUID vectors PASS')
|
|
|
|
if __name__=='__main__':main()
|