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

start using const on internal arguments #665

Merged
merged 1 commit into from
Dec 18, 2023
Merged

Conversation

pabuhler
Copy link
Member

Add const cast warnings.
Add const when the arguments do not need to be modified.

Add const cast warnings.
Add const when the arguments do not need to be modified.
@pabuhler
Copy link
Member Author

This lays the ground work for using const in more places

@@ -212,7 +212,9 @@ static srtp_err_status_t srtp_aes_gcm_nss_context_init(void *cv,
return (srtp_err_status_cipher_fail);
}

SECItem key_item = { siBuffer, (unsigned char *)key, c->key_size };
/* explicitly cast away const of key */
SECItem key_item = { siBuffer, (unsigned char *)(uintptr_t)key,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the compiler is whing too much if this is an issue.

@@ -254,7 +254,9 @@ static srtp_err_status_t srtp_aes_icm_nss_context_init(void *cv,
return srtp_err_status_bad_param;
}

SECItem keyItem = { siBuffer, (unsigned char *)key, c->key_size };
/* explicitly cast away const of key */
SECItem keyItem = { siBuffer, (unsigned char *)(uintptr_t)key,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto here

@@ -187,7 +187,8 @@ static srtp_err_status_t srtp_hmac_init(void *statev,
return srtp_err_status_bad_param;
}

SECItem key_item = { siBuffer, (unsigned char *)key, key_len };
/* explicitly cast away const of key */
SECItem key_item = { siBuffer, (unsigned char *)(uintptr_t)key, key_len };
Copy link
Contributor

Choose a reason for hiding this comment

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

And here

(srtp_hdr_xtnd_t *)((uint32_t *)hdr + uint32s_in_rtp_header +
hdr->cc);
const srtp_hdr_xtnd_t *xtn_hdr =
(const srtp_hdr_xtnd_t *)((const uint32_t *)hdr +
Copy link
Contributor

Choose a reason for hiding this comment

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

Pre-existing, but the double cast here is also a little surprising that it might be necessary. const additions good.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is only because of the usage of uint32s_in_rtp_header, so needs needs the first cast to do the right pointer arithmetic. I have have another change coming that provides some helper functions for the hdr ext stuff as these cast are ugly and murmurous.

int profile_len = ntohs(xtn_hdr->length);
rtp_header_len += profile_len * 4;
/* profile length counts the number of 32-bit words */
if (*pkt_octet_len < rtp_header_len)
if (pkt_octet_len < rtp_header_len)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow. I'm surprised the compiler did not complain about this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

this was due to api change from int * to int

&mki_size);
session_keys =
srtp_get_session_keys(stream, (const uint8_t *)hdr,
(unsigned int)*pkt_octet_len, &mki_size);
Copy link
Contributor

Choose a reason for hiding this comment

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

While this cast might be necessary, why do we have a mix of signed and unsigned integer use? That might be a good thing to harmonize. I personally prefer unsigned integers for length values.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is something we have been looking at and yes we need to harmonize on this and other types, it is coming :)
For length I would even go as far as using size_t every where including in the public api in v3!

@pabuhler pabuhler merged commit 8f54f80 into cisco:main Dec 18, 2023
33 checks passed
@pabuhler pabuhler deleted the const-cast branch December 18, 2023 10:01
mwalbeck pushed a commit to mwalbeck/docker-janus-gateway that referenced this pull request Feb 4, 2025
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cisco/libsrtp](https://github.com/cisco/libsrtp) | minor | `v2.5.0` -> `v2.6.0` |

---

### Release Notes

<details>
<summary>cisco/libsrtp (cisco/libsrtp)</summary>

### [`v2.6.0`](https://github.com/cisco/libsrtp/releases/tag/v2.6.0): libSRTP 2.6.0

[Compare Source](cisco/libsrtp@v2.5.0...v2.6.0)

#### What's Changed

-   cmake: Support configuring as subproject by [@&#8203;yangskyboxlabs](https://github.com/yangskyboxlabs) in cisco/libsrtp#640
-   cmake: Rename TEST_APPS as LIBSRTP_TEST_APPS option by [@&#8203;yangskyboxlabs](https://github.com/yangskyboxlabs) in cisco/libsrtp#641
-   Add a missing typedef for stream list ctx by [@&#8203;Lastique](https://github.com/Lastique) in cisco/libsrtp#643
-   Add x86 SIMD optimizations to crypto datatypes by [@&#8203;Lastique](https://github.com/Lastique) in cisco/libsrtp#507
-   fix typo by [@&#8203;uniontech-lilinjie](https://github.com/uniontech-lilinjie) in cisco/libsrtp#648
-   iv length is constant so set only once by [@&#8203;pabuhler](https://github.com/pabuhler) in cisco/libsrtp#649
-   Fix library version in Doxygen docs by [@&#8203;Lastique](https://github.com/Lastique) in cisco/libsrtp#654
-   remove comma from srtp_profile_t enum value. by [@&#8203;melchi45](https://github.com/melchi45) in cisco/libsrtp#658
-   meson.build: implement mbedtls support by [@&#8203;iameli](https://github.com/iameli) in cisco/libsrtp#660
-   remove travis reference from README.md by [@&#8203;pabuhler](https://github.com/pabuhler) in cisco/libsrtp#661
-   try to use ubuntu-latest by [@&#8203;pabuhler](https://github.com/pabuhler) in cisco/libsrtp#664
-   Some srtp_driver fixes by [@&#8203;pabuhler](https://github.com/pabuhler) in cisco/libsrtp#662
-   Some cipher_driver fixes by [@&#8203;pabuhler](https://github.com/pabuhler) in cisco/libsrtp#663
-   start using const on internal arguments by [@&#8203;pabuhler](https://github.com/pabuhler) in cisco/libsrtp#665
-   Cleaning up cmake and enabled more warnings. by [@&#8203;palerikm](https://github.com/palerikm) in cisco/libsrtp#666
-   fix line break in stream_list.yml by [@&#8203;pabuhler](https://github.com/pabuhler) in cisco/libsrtp#668
-   remove use of pointers to 32bit values by [@&#8203;pabuhler](https://github.com/pabuhler) in cisco/libsrtp#667

#### New Contributors

-   [@&#8203;yangskyboxlabs](https://github.com/yangskyboxlabs) made their first contribution in cisco/libsrtp#640
-   [@&#8203;uniontech-lilinjie](https://github.com/uniontech-lilinjie) made their first contribution in cisco/libsrtp#648
-   [@&#8203;melchi45](https://github.com/melchi45) made their first contribution in cisco/libsrtp#658
-   [@&#8203;iameli](https://github.com/iameli) made their first contribution in cisco/libsrtp#660
-   [@&#8203;palerikm](https://github.com/palerikm) made their first contribution in cisco/libsrtp#666

**Full Changelog**: cisco/libsrtp@v2.5.0...v2.6.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMDIuMSIsInVwZGF0ZWRJblZlciI6IjM5LjE1Ni4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Reviewed-on: https://git.walbeck.it/walbeck-it/docker-janus-gateway/pulls/132
Co-authored-by: renovate-bot <[email protected]>
Co-committed-by: renovate-bot <[email protected]>
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