Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to a class structure #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Move to a class structure #121

wants to merge 1 commit into from

Conversation

jimsch
Copy link
Contributor

@jimsch jimsch commented May 23, 2020

Using classes will make it easier to figure out inheritance issues.

@jimsch
Copy link
Contributor Author

jimsch commented May 23, 2020

@gocarlos I have no idea if the way that I have done things in this PR make any sense. Can you comment?

@@ -27,21 +82,80 @@ typedef struct CounterSign1 COSE_CounterSign1;
#define _countof(x) (sizeof(x) / sizeof(x[0]))
#endif

typedef struct _COSE_KEY {
#ifdef __cplusplus
class COSE_KEY {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say that all internal source code is cpp, so no check needed, public headers should have either a C api or (better) both, modern cpp and ABI stable C api

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this rather than do the conversion on dumper from c to cpp. Otherwise I agree withyou


~COSE_KEY();

int AddRef() { return m_refCount += 1; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why no using shared pointers? this has issues with multi threading, shared pointers solved this already

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not sure how I could use shared pointers. The problem is that we are returning the pointer to C code and then having it call back. I thought that the shared-pointer code was designed for only having the pointer in the class and not moving it back and forth.

static COSE_KEY *KeysRoot;

public:
COSE_KEY()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the naming: I'd keep UPPERCASE_VARS to macros

Copy link
Member

@gocarlos gocarlos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, i think that we should evtl. starting to put some classes and memory mngm inside those classes... doing this with those new operators seems to me in the long run not like improving the existing structure and not well maintanable

@@ -45,63 +45,53 @@ HCOSE_KEY COSE_KEY_FromCbor(cn_cbor *pcborKey,
{
COSE_KEY *pkey = nullptr;

pkey = (COSE_KEY *)COSE_CALLOC(1, sizeof(COSE_KEY), context);

pkey = new (std::nothrow, context) COSE_KEY();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think thia is the way forward...
Better create something like a factory patter which returns a shared ptr.

KeysRoot = pkey;

return (HCOSE_KEY)pkey;
return reinterpret_cast<HCOSE_KEY>(pkey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get rid of all those casts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants