IoObject *IoCertificate_attributes(IoCertificate *self, IoObject *locals, IoMessage *m) { IoObject *map = IoObject_new(IoObject_state(self)); const EVP_PKEY *pkey = X509_extract_key(X509(self)); int i; for(i = 0; i < EVP_PKEY_get_attr_count(pkey); i++) { IoList *list = IoList_new(IoObject_state(self)); X509_ATTRIBUTE *attr = EVP_PKEY_get_attr(pkey, i); const char *key = (const char *)OBJ_nid2ln(OBJ_obj2nid(X509_ATTRIBUTE_get0_object(attr))); int j; for(j = 0; j < X509_ATTRIBUTE_count(attr); j++) { ASN1_TYPE *attrType = X509_ATTRIBUTE_get0_type(attr, j); ASN1_OBJECT *attrData = X509_ATTRIBUTE_get0_data(attr, j, attrType->type, NULL); //consider switching on attrType instead; //really, that would be wiser, so that dates, //numbers, etc can be happy /* switch(attrType->type) { case V_ASN1_OCTET_STRING: ... */ int len = i2t_ASN1_OBJECT(NULL, 0, attrData); char *value = calloc(len, sizeof(char)); i2t_ASN1_OBJECT(value, len, attrData); IoList_rawAppend_(list, IoSeq_newWithCString_(IoObject_state(self), value)); } IoObject_setSlot_to_(map, IOSYMBOL(key), list); } return map; }
IO_METHOD(IoNumber, justAsString) { IoSymbol *string; char *s = IoNumber_asAllocedCString(self); string = IoSeq_newWithCString_((IoState *)IOSTATE, s); io_free(s); return string; }
IoObject *IoCertificate_nameToObject(IoObject *self, X509_NAME *xname) { IoObject *map = IoObject_new(IoObject_state(self)); int i; for(i = 0; i < X509_NAME_entry_count(xname); i++) { X509_NAME_ENTRY *entry = X509_NAME_get_entry(xname, i); const char *key = (const char *)OBJ_nid2ln(OBJ_obj2nid(X509_NAME_ENTRY_get_object(entry))); const char *value = (const char *)ASN1_STRING_data(X509_NAME_ENTRY_get_data(entry)); IoObject_setSlot_to_(map, IOSYMBOL(key), IoSeq_newWithCString_(IoObject_state(self), value)); } return map; }
IoObject *IoCertificate_extensions(IoCertificate *self, IoObject *locals, IoMessage *m) { IoObject *map = IoObject_new(IoObject_state(self)); int i; for(i = 0; i < X509_get_ext_count(X509(self)); i++) { IoObject *ioext = IoObject_new(IoObject_state(self)); X509_EXTENSION *ext = X509_get_ext(X509(self), i); const char *key = (const char *)OBJ_nid2ln(OBJ_obj2nid(X509_EXTENSION_get_object(ext))); const char *value = (const char *)ASN1_STRING_data(X509_EXTENSION_get_data(ext)); int isCritical = X509_EXTENSION_get_critical(ext); IoObject_setSlot_to_(ioext, IOSYMBOL("value"), IoSeq_newWithCString_(IoObject_state(self), value)); IoObject_setSlot_to_(ioext, IOSYMBOL("isCritical"), IONUMBER(isCritical)); IoObject_setSlot_to_(map, IOSYMBOL(key), ioext); } return map; }
IoImage *IoImage_proto(void *state) { IoObject *self = IoObject_new(state); IoObject_tag_(self, IoImage_newTag(state)); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoImageData))); DATA(self)->buffer = IoSeq_newWithCString_(IOSTATE, ""); DATA(self)->image = Image_new(); Image_setExternalUArray_(DATA(self)->image, IoSeq_rawUArray(DATA(self)->buffer)); IoState_registerProtoWithId_(state, self, protoId); { IoMethodTable methodTable[] = { {"setDataWidthHeightComponentCount", IoImage_setDataWidthHeightComponentCount}, {"setPath", IoImage_setPath}, {"open", IoImage_open}, {"save", IoImage_save}, {"width", IoImage_width}, {"height", IoImage_height}, {"data", IoImage_data}, {"componentCount", IoImage_componentCount}, {"isGrayscale", IoImage_isL8}, {"isL8", IoImage_isL8}, {"isLA8", IoImage_isLA8}, {"isRGB8", IoImage_isRGB8}, {"isRGBA8", IoImage_isRGBA8}, {"error", IoImage_error}, {"resizedTo", IoImage_resizedTo}, {"crop", IoImage_crop}, {"addAlpha", IoImage_addAlpha}, {"removeAlpha", IoImage_removeAlpha}, {"makeRGBA8", IoImage_makeRGBA8}, {"makeL8", IoImage_makeL8}, {"makeGrayscale", IoImage_makeGrayscale}, // extras {"setEncodingQuality", IoImage_setEncodingQuality}, {"encodingQuality", IoImage_encodingQuality}, {"setDecodingWidthHint", IoImage_setDecodingWidthHint}, {"decodingWidthHint", IoImage_decodingWidthHint}, {"setDecodingHeightHint", IoImage_setDecodingHeightHint}, {"decodingHeightHint", IoImage_decodingHeightHint}, {"flipX", IoImage_flipX}, {"flipY", IoImage_flipY}, {"baselineHeight", IoImage_baselineHeight}, {"averageColor", IoImage_averageColor}, {"histogram", IoImage_histogram}, {"equalizeHistogram", IoImage_equalizeHistogram}, {"linearContrast", IoImage_linearContrast}, {"bitPlain", IoImage_bitPlain}, {"componentPlain", IoImage_componentPlain}, {"thresholdByGradient", IoImage_thresholdByGradient}, {"thresholdByHistogram", IoImage_thresholdByHistogram}, {"thresholdByOtsu", IoImage_thresholdByOtsu}, {"filterLinear", IoImage_filterLinear}, {"filterUniformAverage", IoImage_filterUniformAverage}, {"filterGauss", IoImage_filterGauss}, {"filterKirsch", IoImage_filterKirsch}, {"filterSobel", IoImage_filterSobel}, {"filterUnsharpMask", IoImage_filterUnsharpMask}, {"filterMin", IoImage_filterMin}, {"filterMax", IoImage_filterMax}, {"filterMedian", IoImage_filterMedian}, {"filterWeightedMedian", IoImage_filterWeightedMedian}, {"bounds", IoImage_bounds}, {NULL, NULL}, }; IoObject_addMethodTable_(self, methodTable); } return self; }