') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); der: enable clippy's panic lints by tarcieri · Pull Request #556 · RustCrypto/formats · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions der/src/asn1/real.rs
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
//! ASN.1 `NULL` support.
//! ASN.1 `REAL` support.

use crate::{
str_slice::StrSlice, ByteSlice, DecodeValue, Decoder, EncodeValue, Encoder, FixedTag, Header,
Length, Result, Tag,
};

use super::integer::uint::strip_leading_zeroes;

// TODO: panic-free implementation
#[allow(clippy::panic_in_result_fn)]
impl DecodeValue<'_> for f64 {
fn decode_value(decoder: &mut Decoder<'_>, header: Header) -> Result<Self> {
let bytes = ByteSlice::decode_value(decoder, header)?.as_bytes();
Expand All@@ -15,8 +18,10 @@ impl DecodeValue<'_> for f64 {
} else if is_nth_bit_one::<7>(bytes) {
// Binary encoding from section 8.5.7 applies
let sign: u64 = if is_nth_bit_one::<6>(bytes) { 1 } else { 0 };

// Section 8.5.7.2: Check the base -- the DER specs say that only base 2 should be supported in DER
let base = mnth_bits_to_u8::<5, 4>(bytes);

if base != 0 {
// Real related error: base is not DER compliant (base encoded in enum)
return Err(Tag::Real.value_error());
Expand DownExpand Up@@ -60,7 +65,9 @@ impl DecodeValue<'_> for f64 {
1 => Ok(f64::NEG_INFINITY),
2 => Ok(f64::NAN),
3 => Ok(-0.0_f64),
_ => unreachable!(),
_ => {
unreachable!()
}
}
} else {
let astr = StrSlice::from_bytes(&bytes[1..])?;
Expand DownExpand Up@@ -158,7 +165,10 @@ impl EncodeValue for f64 {
0 | 1 => {}
2 => first_byte |= 0b0000_0001,
3 => first_byte |= 0b0000_0010,
_ => todo!("support multi octet exponent encoding"),
_ => {
// TODO: support multi octet exponent encoding?
return Err(Tag::Real.value_error());
}
}

encoder.bytes(&[first_byte])?;
Expand Down
3 changes: 3 additions & 0 deletions der/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,8 @@
)]
#![forbid(unsafe_code, clippy::unwrap_used)]
#![warn(
clippy::panic,
clippy::panic_in_result_fn,
missing_docs,
rust_2018_idioms,
unused_lifetimes,
Expand All@@ -25,6 +27,7 @@
//! - [`bool`]: ASN.1 `BOOLEAN`.
//! - [`i8`], [`i16`], [`i32`], [`i64`], [`i128`]: ASN.1 `INTEGER`.
//! - [`u8`], [`u16`], [`u32`], [`u64`], [`u128`]: ASN.1 `INTEGER`.
//! - [`f64`]: ASN.1 `REAL`
//! - [`str`], [`String`][`alloc::string::String`]: ASN.1 `UTF8String`.
//! `String` requires `alloc` feature. See also [`Utf8String`].
//! Requires `alloc` feature. See also [`SetOf`].
Expand Down