pub enum CodeRequirementMatchExpression<'a> {
Show 15 variants
Exists,
Equal(CodeRequirementValue<'a>),
Contains(CodeRequirementValue<'a>),
BeginsWith(CodeRequirementValue<'a>),
EndsWith(CodeRequirementValue<'a>),
LessThan(CodeRequirementValue<'a>),
GreaterThan(CodeRequirementValue<'a>),
LessThanEqual(CodeRequirementValue<'a>),
GreaterThanEqual(CodeRequirementValue<'a>),
On(DateTime<Utc>),
Before(DateTime<Utc>),
After(DateTime<Utc>),
OnOrBefore(DateTime<Utc>),
OnOrAfter(DateTime<Utc>),
Absent,
}Expand description
An instance of a match expression in a CodeRequirementExpression.
Variants§
Exists
Entity exists.
exists
No payload.
Equal(CodeRequirementValue<'a>)
Equality.
= <value>
4 bytes length, raw data.
Contains(CodeRequirementValue<'a>)
Contains.
~ <value>
4 bytes length, raw data.
BeginsWith(CodeRequirementValue<'a>)
Begins with.
= <value>*
4 bytes length, raw data.
EndsWith(CodeRequirementValue<'a>)
Ends with.
= *<value>
4 bytes length, raw data.
LessThan(CodeRequirementValue<'a>)
Less than.
< <value>
4 bytes length, raw data.
GreaterThan(CodeRequirementValue<'a>)
Greater than.
> <value>
LessThanEqual(CodeRequirementValue<'a>)
Less than or equal to.
<= <value>
4 bytes length, raw data.
GreaterThanEqual(CodeRequirementValue<'a>)
Greater than or equal to.
>= <value>
4 bytes length, raw data.
On(DateTime<Utc>)
Timestamp value equivalent.
= timestamp "<timestamp>"
Before(DateTime<Utc>)
Timestamp value before.
< timestamp "<timestamp>"
After(DateTime<Utc>)
Timestamp value after.
> timestamp "<timestamp>"
OnOrBefore(DateTime<Utc>)
Timestamp value equivalent or before.
<= timestamp "<timestamp>"
OnOrAfter(DateTime<Utc>)
Timestamp value equivalent or after.
>= timestamp "<timestamp>"
Absent
Value is absent.
<empty>
No payload.
Implementations§
source§impl<'a> CodeRequirementMatchExpression<'a>
impl<'a> CodeRequirementMatchExpression<'a>
sourcepub fn from_bytes(
data: &'a [u8]
) -> Result<(Self, &'a [u8]), AppleCodesignError>
pub fn from_bytes(
data: &'a [u8]
) -> Result<(Self, &'a [u8]), AppleCodesignError>
Parse a match expression from bytes.
The slice should begin with the match type u32.
Examples found in repository?
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
pub fn parse_payload<'a>(
&self,
data: &'a [u8],
) -> Result<(CodeRequirementExpression<'a>, &'a [u8]), AppleCodesignError> {
match self {
Self::False => Ok((CodeRequirementExpression::False, data)),
Self::True => Ok((CodeRequirementExpression::True, data)),
Self::Identifier => {
let (value, data) = read_data(data)?;
let s = std::str::from_utf8(value).map_err(|_| {
AppleCodesignError::RequirementMalformed("identifier value not a UTF-8 string")
})?;
Ok((CodeRequirementExpression::Identifier(Cow::from(s)), data))
}
Self::AnchorApple => Ok((CodeRequirementExpression::AnchorApple, data)),
Self::AnchorCertificateHash => {
let slot = data.pread_with::<i32>(0, scroll::BE)?;
let digest_length = data.pread_with::<u32>(4, scroll::BE)?;
let digest = &data[8..8 + digest_length as usize];
Ok((
CodeRequirementExpression::AnchorCertificateHash(slot, digest.into()),
&data[8 + digest_length as usize..],
))
}
Self::InfoKeyValueLegacy => {
let (key, data) = read_data(data)?;
let key = std::str::from_utf8(key).map_err(|_| {
AppleCodesignError::RequirementMalformed("info key not a UTF-8 string")
})?;
let (value, data) = read_data(data)?;
let value = std::str::from_utf8(value).map_err(|_| {
AppleCodesignError::RequirementMalformed("info value not a UTF-8 string")
})?;
Ok((
CodeRequirementExpression::InfoKeyValueLegacy(key.into(), value.into()),
data,
))
}
Self::And => {
let (a, data) = CodeRequirementExpression::from_bytes(data)?;
let (b, data) = CodeRequirementExpression::from_bytes(data)?;
Ok((
CodeRequirementExpression::And(Box::new(a), Box::new(b)),
data,
))
}
Self::Or => {
let (a, data) = CodeRequirementExpression::from_bytes(data)?;
let (b, data) = CodeRequirementExpression::from_bytes(data)?;
Ok((
CodeRequirementExpression::Or(Box::new(a), Box::new(b)),
data,
))
}
Self::CodeDirectoryHash => {
let (value, data) = read_data(data)?;
Ok((
CodeRequirementExpression::CodeDirectoryHash(value.into()),
data,
))
}
Self::Not => {
let (expr, data) = CodeRequirementExpression::from_bytes(data)?;
Ok((CodeRequirementExpression::Not(Box::new(expr)), data))
}
Self::InfoPlistExpression => {
let (key, data) = read_data(data)?;
let key = std::str::from_utf8(key).map_err(|_| {
AppleCodesignError::RequirementMalformed("key is not valid UTF-8")
})?;
let (expr, data) = CodeRequirementMatchExpression::from_bytes(data)?;
Ok((
CodeRequirementExpression::InfoPlistKeyField(key.into(), expr),
data,
))
}
Self::CertificateField => {
let slot = data.pread_with::<i32>(0, scroll::BE)?;
let (field, data) = read_data(&data[4..])?;
let field = std::str::from_utf8(field).map_err(|_| {
AppleCodesignError::RequirementMalformed("certificate field is not valid UTF-8")
})?;
let (expr, data) = CodeRequirementMatchExpression::from_bytes(data)?;
Ok((
CodeRequirementExpression::CertificateField(slot, field.into(), expr),
data,
))
}
Self::CertificateTrusted => {
let slot = data.pread_with::<i32>(0, scroll::BE)?;
Ok((
CodeRequirementExpression::CertificateTrusted(slot),
&data[4..],
))
}
Self::AnchorTrusted => Ok((CodeRequirementExpression::AnchorTrusted, data)),
Self::CertificateGeneric => {
let slot = data.pread_with::<i32>(0, scroll::BE)?;
let (oid, data) = read_data(&data[4..])?;
let (expr, data) = CodeRequirementMatchExpression::from_bytes(data)?;
Ok((
CodeRequirementExpression::CertificateGeneric(slot, Oid(oid), expr),
data,
))
}
Self::AnchorAppleGeneric => Ok((CodeRequirementExpression::AnchorAppleGeneric, data)),
Self::EntitlementsField => {
let (key, data) = read_data(data)?;
let key = std::str::from_utf8(key).map_err(|_| {
AppleCodesignError::RequirementMalformed("entitlement key is not UTF-8")
})?;
let (expr, data) = CodeRequirementMatchExpression::from_bytes(data)?;
Ok((
CodeRequirementExpression::EntitlementsKey(key.into(), expr),
data,
))
}
Self::CertificatePolicy => {
let slot = data.pread_with::<i32>(0, scroll::BE)?;
let (oid, data) = read_data(&data[4..])?;
let (expr, data) = CodeRequirementMatchExpression::from_bytes(data)?;
Ok((
CodeRequirementExpression::CertificatePolicy(slot, Oid(oid), expr),
data,
))
}
Self::NamedAnchor => {
let (name, data) = read_data(data)?;
let name = std::str::from_utf8(name).map_err(|_| {
AppleCodesignError::RequirementMalformed("named anchor isn't UTF-8")
})?;
Ok((CodeRequirementExpression::NamedAnchor(name.into()), data))
}
Self::NamedCode => {
let (name, data) = read_data(data)?;
let name = std::str::from_utf8(name).map_err(|_| {
AppleCodesignError::RequirementMalformed("named code isn't UTF-8")
})?;
Ok((CodeRequirementExpression::NamedCode(name.into()), data))
}
Self::Platform => {
let value = data.pread_with::<u32>(0, scroll::BE)?;
Ok((CodeRequirementExpression::Platform(value), &data[4..]))
}
Self::Notarized => Ok((CodeRequirementExpression::Notarized, data)),
Self::CertificateFieldDate => {
let slot = data.pread_with::<i32>(0, scroll::BE)?;
let (oid, data) = read_data(&data[4..])?;
let (expr, data) = CodeRequirementMatchExpression::from_bytes(data)?;
Ok((
CodeRequirementExpression::CertificateFieldDate(slot, Oid(oid), expr),
data,
))
}
Self::LegacyDeveloperId => Ok((CodeRequirementExpression::LegacyDeveloperId, data)),
}
}sourcepub fn write_to(&self, dest: &mut impl Write) -> Result<(), AppleCodesignError>
pub fn write_to(&self, dest: &mut impl Write) -> Result<(), AppleCodesignError>
Write binary representation of this match expression to a destination.
Examples found in repository?
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
pub fn write_to(&self, dest: &mut impl Write) -> Result<(), AppleCodesignError> {
dest.iowrite_with(RequirementOpCode::from(self) as u32, scroll::BE)?;
match self {
Self::False => {}
Self::True => {}
Self::Identifier(s) => {
write_data(dest, s.as_bytes())?;
}
Self::AnchorApple => {}
Self::AnchorCertificateHash(slot, hash) => {
dest.iowrite_with(*slot, scroll::BE)?;
write_data(dest, hash)?;
}
Self::InfoKeyValueLegacy(key, value) => {
write_data(dest, key.as_bytes())?;
write_data(dest, value.as_bytes())?;
}
Self::And(a, b) => {
a.write_to(dest)?;
b.write_to(dest)?;
}
Self::Or(a, b) => {
a.write_to(dest)?;
b.write_to(dest)?;
}
Self::CodeDirectoryHash(hash) => {
write_data(dest, hash)?;
}
Self::Not(expr) => {
expr.write_to(dest)?;
}
Self::InfoPlistKeyField(key, m) => {
write_data(dest, key.as_bytes())?;
m.write_to(dest)?;
}
Self::CertificateField(slot, field, m) => {
dest.iowrite_with(*slot, scroll::BE)?;
write_data(dest, field.as_bytes())?;
m.write_to(dest)?;
}
Self::CertificateTrusted(slot) => {
dest.iowrite_with(*slot, scroll::BE)?;
}
Self::AnchorTrusted => {}
Self::CertificateGeneric(slot, oid, m) => {
dest.iowrite_with(*slot, scroll::BE)?;
write_data(dest, oid.as_ref())?;
m.write_to(dest)?;
}
Self::AnchorAppleGeneric => {}
Self::EntitlementsKey(key, m) => {
write_data(dest, key.as_bytes())?;
m.write_to(dest)?;
}
Self::CertificatePolicy(slot, oid, m) => {
dest.iowrite_with(*slot, scroll::BE)?;
write_data(dest, oid.as_ref())?;
m.write_to(dest)?;
}
Self::NamedAnchor(value) => {
write_data(dest, value.as_bytes())?;
}
Self::NamedCode(value) => {
write_data(dest, value.as_bytes())?;
}
Self::Platform(value) => {
dest.iowrite_with(*value, scroll::BE)?;
}
Self::Notarized => {}
Self::CertificateFieldDate(slot, oid, m) => {
dest.iowrite_with(*slot, scroll::BE)?;
write_data(dest, oid.as_ref())?;
m.write_to(dest)?;
}
Self::LegacyDeveloperId => {}
}
Ok(())
}Trait Implementations§
source§impl<'a> Clone for CodeRequirementMatchExpression<'a>
impl<'a> Clone for CodeRequirementMatchExpression<'a>
source§fn clone(&self) -> CodeRequirementMatchExpression<'a>
fn clone(&self) -> CodeRequirementMatchExpression<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'a> Debug for CodeRequirementMatchExpression<'a>
impl<'a> Debug for CodeRequirementMatchExpression<'a>
source§impl<'a> Display for CodeRequirementMatchExpression<'a>
impl<'a> Display for CodeRequirementMatchExpression<'a>
source§impl<'a> PartialEq<CodeRequirementMatchExpression<'a>> for CodeRequirementMatchExpression<'a>
impl<'a> PartialEq<CodeRequirementMatchExpression<'a>> for CodeRequirementMatchExpression<'a>
source§fn eq(&self, other: &CodeRequirementMatchExpression<'a>) -> bool
fn eq(&self, other: &CodeRequirementMatchExpression<'a>) -> bool
self and other values to be equal, and is used
by ==.impl<'a> Eq for CodeRequirementMatchExpression<'a>
impl<'a> StructuralEq for CodeRequirementMatchExpression<'a>
impl<'a> StructuralPartialEq for CodeRequirementMatchExpression<'a>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for CodeRequirementMatchExpression<'a>
impl<'a> Send for CodeRequirementMatchExpression<'a>
impl<'a> Sync for CodeRequirementMatchExpression<'a>
impl<'a> Unpin for CodeRequirementMatchExpression<'a>
impl<'a> UnwindSafe for CodeRequirementMatchExpression<'a>
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<T> Conv for T
impl<T> Conv for T
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
self, then passes self.as_mut() into the pipe
function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
.tap_ref_mut() only in debug builds, and is erased in release
builds.