int load_arg(struct katcl_line *l, char *arg, int fmt, int flags) { unsigned char *tmp; int len, i, j, v, result; switch(fmt){ case FMT_BIN : case FMT_TEXT : return append_string_katcl(l, flags, arg); case FMT_AUTO : case FMT_HEX : if(strncmp(arg, "0x", 2)){ return append_string_katcl(l, flags, arg); } else { len = strlen(arg + 2); if(len % 2){ fprintf(stderr, "warning: argument %s contains an odd number of hex characters, ignoring the trailing one\n", arg); len--; } len = len / 2; if(len == 0){ /* NULL parameters are really bad form */ return append_buffer_katcl(l, flags, NULL, 0); } tmp = malloc(len); if(tmp == NULL){ fprintf(stderr, "warning: argument %s contains an odd number of hex characters, ignoring the trailing one\n", arg); return -1; } j = 2; for(i = 0; i < len; i++){ v = h2n(arg[j++]); if(v < 0){ free(tmp); return -1; } tmp[i] = 0xf0 & (v << 4); v = h2n(arg[j++]); if(v < 0){ free(tmp); return -1; } tmp[i] |= 0x0f & v; } result = append_buffer_katcl(l, flags, tmp, len); free(tmp); return result; } break; default : fprintf(stderr, "error: unhandled format %d\n", fmt); return -1; } }
void ThresholdAclSubject::exportBlobForm(Action &pub, Action &priv) { pub(h2n(totalSubjects)); pub(h2n(minimumNeeded)); for (uint32 n = 0; n < totalSubjects; n++) ObjectAcl::exportSubject(elements[n], pub, priv); }
static char *read_data(const char *asc, int *retlen) { char *p; int len=0, binlen=0, alloclen=RESIZE; p = (char*)malloc(alloclen); if (!p) return NULL; *retlen = 0; while(asc[len] != '\0') { p[binlen] = (h2n(asc[len])<<4) + h2n(asc[len+1]); len +=2; binlen++; if (binlen == alloclen) { alloclen +=RESIZE; p = (char *)realloc(p, alloclen); } } *retlen = binlen; return p; }
void Guid::parseGuid(const char *string) { // Arguably, we should be more flexible on input. But exactly what // padding rules should we follow, and how should we try to interprete // "doubtful" variations? Given that GUIDs are essentially magic // cookies, everybody's better off if we just cut-and-paste them // around the universe... // do sanity checking, don't assume that what's passed in makes sense if (string == NULL) { CssmError::throwMe(CSSM_ERRCODE_INVALID_GUID); } // what follows had better be big enough if (strlen(string) < 37) // needed because the code hard codes the length { CssmError::throwMe(CSSM_ERRCODE_INVALID_GUID); } int d1; uint16 d2, d3; if (sscanf(string, "{%8x-%4hx-%4hx-", &d1, &d2, &d3) != 3) CssmError::throwMe(CSSM_ERRCODE_INVALID_GUID); Data1 = h2n(uint32(d1)); Data2 = h2n(d2); Data3 = h2n(d3); // once, we did not expect the - after byte 2 of Data4 bool newForm = string[24] == '-'; for (int n = 0; n < 8; n++) { unsigned char dn; if (sscanf(string + 20 + 2*n + (newForm && n >= 2), "%2hhx", &dn) != 1) CssmError::throwMe(CSSM_ERRCODE_INVALID_GUID); Data4[n] = dn; } if (string[37 - !newForm] != '}') CssmError::throwMe(CSSM_ERRCODE_INVALID_GUID); }