hillu / go-yara

Go bindings for YARA
BSD 2-Clause "Simplified" License
350 stars 112 forks source link

There's no way to return an error from MemoryBlockIterator #118

Open smoofra opened 1 year ago

smoofra commented 1 year ago

In C, a YR_MEMORY_BLOCK_ITERATOR can set last_error from its iteration functions in order to return an error, but this doesn't seem to be accessible from go.

hillu commented 1 year ago

Guilty as charged. ;-) I think this was added to YARA for 4.1.0, after I had done the iterator code. Just like file_size.

I have added another interface, MemoryBlockIterator in the iterator-last-error branch. Would you like to have a look if this works for you – and maybe contribute a test case for this? Thanks!

smoofra commented 1 year ago

thanks for responding! What you've got would work, but I think returning an error directly from First() and Next() would be more go-like and easier to use. What do you think?

hillu commented 1 year ago

Making First, Next return an error would break the API. Perhaps for version 5.0.

smoofra commented 1 year ago

doesn't adding a new method to the interface also break the API?

hillu commented 1 year ago

doesn't adding a new method to the interface also break the API?

No. For code using go-yara, implementing the extra interface is optional.

Even though this is not the most (Golang-)idiomatic way to signal an error, I can't think of a better alternative. Would you like to contirbute a test case?