void BStream_writeTaggedData_length_(BStream *self, const unsigned char *data, size_t length) { BStream_writeTag(self, BSTREAM_UNSIGNED_INT, 1, 1); BStream_writeTaggedInt32_(self, length); UArray_appendBytes_size_(self->ba, (unsigned char *)data, length); self->index += length; }
void AudioDevice_writeData_length_(AudioDevice *self, uint8_t *data, size_t numBytes) { self->writeBufferIsEmpty = 0; AudioDevice_lock(self); UArray_appendBytes_size_(self->nextWriteBuffer, data, numBytes); self->needsData = 0; //printf("writting self->needsData = 0\n"); AudioDevice_unlock(self); AudioDevice_start(self); }
void BStream_writeNumber_size_(BStream *self, unsigned char *v, size_t length) { memcpy(self->typeBuf, v, length); if (self->flipEndian) { reverseBytes(self->typeBuf, length); } UArray_appendBytes_size_(self->ba, (unsigned char *)self->typeBuf, length); self->index += length; }
UArray *UArray_asNumberArrayString(const UArray *self) { UArray *out = UArray_new(); UArray_setEncoding_(out, CENCODING_ASCII); UARRAY_INTFOREACH(self, i, v, char s[128]; if(UArray_isFloatType(self)) { sprintf(s, "%f", (double)v); } else { sprintf(s, "%i", (int)v); } if(i != UArray_size(self) -1 ) strcat(s, ", "); UArray_appendBytes_size_(out, (unsigned char *)s, strlen(s)); );
IoObject *IoBlowfish_process(IoBlowfish *self, IoObject *locals, IoMessage *m) { /*doc Blowfish process Process the inputBuffer and appends the result to the outputBuffer. The processed inputBuffer is empties except for the spare bytes at the end which don't fit into a cipher block. */ blowfish_ctx *context = &(DATA(self)->context); int isEncrypting = DATA(self)->isEncrypting; UArray *input = IoObject_rawGetMutableUArraySlot(self, locals, m, IOSYMBOL("inputBuffer")); UArray *output = IoObject_rawGetMutableUArraySlot(self, locals, m, IOSYMBOL("outputBuffer")); const unsigned char *inputBytes = (uint8_t *)UArray_bytes(input); size_t inputSize = UArray_sizeInBytes(input); unsigned long lr[2]; size_t i, runs = inputSize / sizeof(lr); for (i = 0; i < runs; i ++) { memcpy(lr, inputBytes, sizeof(lr)); inputBytes += sizeof(lr); if (isEncrypting) { blowfish_encrypt(context, &lr[0], &lr[1]); } else { blowfish_decrypt(context, &lr[0], &lr[1]); } UArray_appendBytes_size_(output, (unsigned char *)&lr, sizeof(lr)); } UArray_removeRange(input, 0, runs * sizeof(lr)); return self; }
IoObject *IoBlowfish_endProcessing(IoBlowfish *self, IoObject *locals, IoMessage *m) { /*doc Blowfish endProcessing Finish processing remaining bytes of inputBuffer. */ blowfish_ctx *context = &(DATA(self)->context); unsigned long lr[2]; IoBlowfish_process(self, locals, m); // process the full blocks first { int isEncrypting = DATA(self)->isEncrypting; UArray *input = IoObject_rawGetMutableUArraySlot(self, locals, m, IOSYMBOL("inputBuffer")); UArray *output = IoObject_rawGetMutableUArraySlot(self, locals, m, IOSYMBOL("outputBuffer")); IOASSERT(UArray_sizeInBytes(input) < sizeof(lr), "internal error - too many bytes left in inputBuffer"); memset(lr, 0, sizeof(lr)); memcpy(lr, (uint8_t *)UArray_bytes(input), UArray_sizeInBytes(input)); if (isEncrypting) { blowfish_encrypt(context, &lr[0], &lr[1]); } else { blowfish_decrypt(context, &lr[0], &lr[1]); } UArray_appendBytes_size_(output, (unsigned char *)&lr, sizeof(lr)); UArray_setSize_(input, 0); } return self; }
void BStream_writeData_length_(BStream *self, const unsigned char *data, size_t length) { UArray_appendBytes_size_(self->ba, (unsigned char *)data, length); self->index += length; }