| 5071 | |
| 5072 | |
| 5073 | dsc* evlHash(thread_db* tdbb, const SysFunction* function, const NestValueArray& args, |
| 5074 | impure_value* impure) |
| 5075 | { |
| 5076 | fb_assert(args.getCount() >= 1); |
| 5077 | |
| 5078 | Request* request = tdbb->getRequest(); |
| 5079 | |
| 5080 | const dsc* value = EVL_expr(tdbb, request, args[0]); |
| 5081 | if (request->req_flags & req_null) // return NULL if value is NULL |
| 5082 | return NULL; |
| 5083 | |
| 5084 | AutoPtr<HashContext> hashContext; |
| 5085 | MemoryPool& pool = *request->req_pool; |
| 5086 | |
| 5087 | if (args.getCount() >= 2) |
| 5088 | { |
| 5089 | const dsc* algorithmDesc = EVL_expr(tdbb, request, args[1]); |
| 5090 | if (request->req_flags & req_null) // return NULL if algorithm is NULL |
| 5091 | return NULL; |
| 5092 | |
| 5093 | const HashAlgorithmDescriptor* d = getHashAlgorithmDesc(tdbb, function, algorithmDesc); |
| 5094 | hashContext.reset(d->create(pool)); |
| 5095 | } |
| 5096 | else |
| 5097 | { |
| 5098 | hashContext.reset(FB_NEW_POOL(pool) WeakHashContext()); |
| 5099 | impure->vlu_misc.vlu_int64 = 0; |
| 5100 | } |
| 5101 | |
| 5102 | if (value->isBlob()) |
| 5103 | { |
| 5104 | UCHAR buffer[BUFFER_LARGE]; |
| 5105 | blb* blob = blb::open(tdbb, tdbb->getRequest()->req_transaction, |
| 5106 | reinterpret_cast<bid*>(value->dsc_address)); |
| 5107 | |
| 5108 | while (!(blob->blb_flags & BLB_eof)) |
| 5109 | { |
| 5110 | const ULONG length = blob->BLB_get_data(tdbb, buffer, sizeof(buffer), false); |
| 5111 | hashContext->update(buffer, length); |
| 5112 | } |
| 5113 | |
| 5114 | blob->BLB_close(tdbb); |
| 5115 | } |
| 5116 | else |
| 5117 | { |
| 5118 | UCHAR* address; |
| 5119 | MoveBuffer buffer; |
| 5120 | const ULONG length = MOV_make_string2(tdbb, value, value->getTextType(), &address, buffer, false); |
| 5121 | hashContext->update(address, length); |
| 5122 | } |
| 5123 | |
| 5124 | dsc result; |
| 5125 | hashContext->finish(result); |
| 5126 | EVL_make_value(tdbb, &result, impure); |
| 5127 | |
| 5128 | return &impure->vlu_desc; |
| 5129 | } |
| 5130 |
nothing calls this directly
no test coverage detected