pub type Result<T, E = VerifyError> = core::result::Result<T, E>;
#[derive(Debug, thiserror::Error, PartialEq)]
pub enum VerifyError {
#[error("ClassFormatError: {0}")]
ClassFormatError(String),
#[error("IllegalAccessError: {0}")]
IllegalAccessError(String),
#[error("IncompatibleClassChangeError: {0}")]
IncompatibleClassChangeError(String),
#[error("NoClassDefFoundError: {0}")]
NoClassDefFoundError(String),
#[error("BootstrapMethods attribute not defined in class file")]
BootstrapMethodsNotDefined,
#[error("Invalid annotation element tag: {0}")]
InvalidAnnotationElementTag(u8),
#[error("Invalid array type code {0}")]
InvalidArrayTypeCode(u8),
#[error("Invalid attribute length: {0}")]
InvalidAttributeLength(u32),
#[error("Invalid attribute name index: {0}")]
InvalidAttributeNameIndex(u16),
#[error("Invalid base type code {0}")]
InvalidBaseTypeCode(char),
#[error("Invalid bootstrap method index {0}")]
InvalidBootstrapMethodIndex(usize),
#[error("Invalid class access flags: {0}")]
InvalidClassAccessFlags(u16),
#[error("Invalid constant pool index {0}")]
InvalidConstantPoolIndex(u16),
#[error("Invalid constant pool index type {0}")]
InvalidConstantPoolIndexType(u16),
#[error("Invalid constant tag: {0}")]
InvalidConstantTag(u8),
#[error("Invalid field access flags: {0}")]
InvalidFieldAccessFlags(u16),
#[error("Invalid field type code {0}")]
InvalidFieldTypeCode(char),
#[error("Invalid field type descriptor {0}")]
InvalidFieldTypeDescriptor(String),
#[error("Invalid instruction: {0}")]
InvalidInstruction(u8),
#[error("Invalid instruction offset: {0}")]
InvalidInstructionOffset(u32),
#[error("Invalid method access flags: {0}")]
InvalidMethodAccessFlags(u16),
#[error("Invalid method descriptor: {0}")]
InvalidMethodDescriptor(String),
#[error("Invalid reference kind: {0}")]
InvalidReferenceKind(u8),
#[error("Invalid stack frame type: {0}")]
InvalidStackFrameType(u8),
#[error("Invalid stack frame offset: {0}")]
InvalidStackFrameOffset(u16),
#[error("Invalid target type code {0}")]
InvalidTargetTypeCode(u8),
#[error("Invalid verification type tag: {0}")]
InvalidVerificationTypeTag(u8),
#[error("Class file version does not support constant tag {0}")]
InvalidVersionConstant(u8),
#[error("Invalid wide instruction: {0}")]
InvalidWideInstruction(u8),
#[error(transparent)]
TryFromIntError(#[from] std::num::TryFromIntError),
#[error("UnsupportedClassVersionError: {0}")]
UnsupportedClassVersionError(String),
#[error("VerifyError: {0}")]
VerifyError(String),
#[error("VerifyError: {context}: {message}")]
VerificationError { context: String, message: String },
}
impl From<crate::Error> for VerifyError {
fn from(error: crate::Error) -> Self {
match error {
crate::Error::InvalidAnnotationElementTag(tag) => {
VerifyError::InvalidAnnotationElementTag(tag)
}
crate::Error::InvalidArrayTypeCode(code) => VerifyError::InvalidArrayTypeCode(code),
crate::Error::InvalidAttributeLength(len) => VerifyError::InvalidAttributeLength(len),
crate::Error::InvalidAttributeNameIndex(idx) => {
VerifyError::InvalidAttributeNameIndex(idx)
}
crate::Error::InvalidBaseTypeCode(code) => VerifyError::InvalidBaseTypeCode(code),
crate::Error::InvalidConstantPoolIndex(idx) => {
VerifyError::InvalidConstantPoolIndex(idx)
}
crate::Error::InvalidConstantPoolIndexType(idx) => {
VerifyError::InvalidConstantPoolIndexType(idx)
}
crate::Error::InvalidConstantTag(tag) => VerifyError::InvalidConstantTag(tag),
crate::Error::InvalidFieldTypeCode(code) => VerifyError::InvalidFieldTypeCode(code),
crate::Error::InvalidFieldTypeDescriptor(desc) => {
VerifyError::InvalidFieldTypeDescriptor(desc)
}
crate::Error::InvalidInstruction(code) => VerifyError::InvalidInstruction(code),
crate::Error::InvalidInstructionOffset(offset) => {
VerifyError::InvalidInstructionOffset(offset)
}
crate::Error::InvalidMethodDescriptor(desc) => {
VerifyError::InvalidMethodDescriptor(desc)
}
crate::Error::InvalidReferenceKind(kind) => VerifyError::InvalidReferenceKind(kind),
crate::Error::InvalidStackFrameType(tag) => VerifyError::InvalidStackFrameType(tag),
crate::Error::InvalidTargetTypeCode(code) => VerifyError::InvalidTargetTypeCode(code),
crate::Error::InvalidVerificationTypeTag(tag) => {
VerifyError::InvalidVerificationTypeTag(tag)
}
crate::Error::InvalidWideInstruction(code) => VerifyError::InvalidWideInstruction(code),
crate::Error::TryFromIntError(err) => VerifyError::TryFromIntError(err),
crate::Error::VerificationError(error) => error,
_ => VerifyError::VerifyError(error.to_string()),
}
}
}