hbytes_free(OBJ_HBYTES(o));
}
-void obj_updatestr_array(Tcl_Obj *o, const Byte *byte, int l) {
+void obj_updatestr_array_prefix(Tcl_Obj *o, const Byte *byte,
+ int l, const char *prefix) {
char *str;
+ int pl;
+
+ pl= strlen(prefix);
+ o->length= l*2+pl;
+ str= o->bytes= TALLOC(o->length+1);
+
+ memcpy(str,prefix,pl);
+ str += pl;
- str= o->bytes= TALLOC(l*2+1);
- o->length= l*2;
while (l>0) {
sprintf(str,"%02x",*byte);
str+=2; byte++; l--;
*str= 0;
}
+void obj_updatestr_array(Tcl_Obj *o, const Byte *byte, int l) {
+ obj_updatestr_array_prefix(o,byte,l,"");
+}
+
static void hbytes_t_ustr(Tcl_Obj *o) {
obj_updatestr_array(o,
hbytes_data(OBJ_HBYTES(o)),
return TCL_OK;
}
+int do_hbytes_random(ClientData cd, Tcl_Interp *ip,
+ int length, HBytes_Value *result) {
+ Byte *space;
+ int rc;
+
+ space= hbytes_arrayspace(result, length);
+ rc= get_urandom(ip, space, length);
+ if (rc) { hbytes_free(result); return rc; }
+ return TCL_OK;
+}
+
+int do_hbytes_zeroes(ClientData cd, Tcl_Interp *ip,
+ int length, HBytes_Value *result) {
+ Byte *space;
+ space= hbytes_arrayspace(result, length);
+ memset(space,0,length);
+ return TCL_OK;
+}
+
int do__hbytes(ClientData cd, Tcl_Interp *ip,
const HBytes_SubCommand *subcmd,
int objc, Tcl_Obj *const *objv) {
return subcmd->func(0,ip,objc,objv);
}
+int do__dgram_socket(ClientData cd, Tcl_Interp *ip,
+ const DgramSocket_SubCommand *subcmd,
+ int objc, Tcl_Obj *const *objv) {
+ return subcmd->func(0,ip,objc,objv);
+}
+
#define URANDOM "/dev/urandom"
int get_urandom(Tcl_Interp *ip, Byte *buffer, int l) {
Tcl_RegisterObjType(&blockcipherkey_type);
Tcl_RegisterObjType(&enum_nearlytype);
Tcl_RegisterObjType(&enum1_nearlytype);
- Tcl_CreateObjCommand(ip,"hbytes", pa__hbytes,0,0);
+ Tcl_RegisterObjType(&sockaddr_type);
+ Tcl_RegisterObjType(&sockid_type);
+ Tcl_CreateObjCommand(ip, "hbytes", pa__hbytes, 0,0);
+ Tcl_CreateObjCommand(ip, "dgram-socket", pa__dgram_socket, 0,0);
return TCL_OK;
}