C # Mixed unsafe / secure library

I am slowly building a code library for use in multiple applications. Some of the code processes images and pre-existing message formats (converted from C ++), so unsafe code is required.

Any reasons why I should NOT mix unsafe and secure code in the same library assembly more than I need?

In other words: should I keep a clean library and collect unsafe code in another library / libraries?

I appreciate that there are trust issues that should be considered when using "unsafe" libraries, but since these functions are crucial for most of my applications, does it really matter? Any of my code, safe and insecure, is trusted or not trusted, and my application will not work. Or am I missing a point?

+4
source share
1 answer

In theory, you can develop what you need in safe code, but let me assume that you have good reason to use unsafe code :)

In the parts of the code in which you run unsafe code, you risk forgetting to free up memory, etc., so if you manage the memory well, you should have no problem. When you have a C # project using COM + dll, you do this all the time. It’s better in your case, because you own all the code so that you can fix any memory leak if you can detect it.

If you collect all unsafe codes in a separate library

PROFI

  • You can create a new secure library in the future.
  • If you see that the dll does not work in the execution logs, you can more easily isolate the source of the problem.

Cons

  • Deteriorated reading of your code if you need to split safe / insecure code in an unnatural way.

So, your honest decision. If I were you, I would split the unsafe code into another project, in order to be able to replace it with safe code if necessary.

+4
source

All Articles