X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FDecodeError.java;h=39e16610a7a25467be48b58a3fdbaa0321e7c54e;hb=5d91c4ade4b5f736d100428ccf84709ad29f971d;hp=0dc34a05f7d2458b6984e6db86a9f96f2b571574;hpb=330ca992be304d0eac79bd59b411980dff294b03;p=ldk-java diff --git a/src/main/java/org/ldk/structs/DecodeError.java b/src/main/java/org/ldk/structs/DecodeError.java index 0dc34a05..39e16610 100644 --- a/src/main/java/org/ldk/structs/DecodeError.java +++ b/src/main/java/org/ldk/structs/DecodeError.java @@ -42,12 +42,16 @@ public class DecodeError extends CommonBase { if (raw_val.getClass() == bindings.LDKDecodeError.UnsupportedCompression.class) { return new UnsupportedCompression(ptr, (bindings.LDKDecodeError.UnsupportedCompression)raw_val); } + if (raw_val.getClass() == bindings.LDKDecodeError.DangerousValue.class) { + return new DangerousValue(ptr, (bindings.LDKDecodeError.DangerousValue)raw_val); + } assert false; return null; // Unreachable without extending the (internal) bindings interface } /** * A version byte specified something we don't know how to handle. - * Includes unknown realm byte in an OnionHopData packet + * + * Includes unknown realm byte in an onion hop data packet. */ public final static class UnknownVersion extends DecodeError { private UnknownVersion(long ptr, bindings.LDKDecodeError.UnknownVersion obj) { @@ -55,7 +59,7 @@ public class DecodeError extends CommonBase { } } /** - * Unknown feature mandating we fail to parse message (eg TLV with an even, unknown type) + * Unknown feature mandating we fail to parse message (e.g., TLV with an even, unknown type) */ public final static class UnknownRequiredFeature extends DecodeError { private UnknownRequiredFeature(long ptr, bindings.LDKDecodeError.UnknownRequiredFeature obj) { @@ -63,9 +67,11 @@ public class DecodeError extends CommonBase { } } /** - * Value was invalid, eg a byte which was supposed to be a bool was something other than a 0 + * Value was invalid. + * + * For example, a byte which was supposed to be a bool was something other than a 0 * or 1, a public key/private key/signature was invalid, text wasn't UTF-8, TLV was - * syntactically incorrect, etc + * syntactically incorrect, etc. */ public final static class InvalidValue extends DecodeError { private InvalidValue(long ptr, bindings.LDKDecodeError.InvalidValue obj) { @@ -73,7 +79,7 @@ public class DecodeError extends CommonBase { } } /** - * Buffer too short + * The buffer to be read was too short. */ public final static class ShortRead extends DecodeError { private ShortRead(long ptr, bindings.LDKDecodeError.ShortRead obj) { @@ -81,7 +87,7 @@ public class DecodeError extends CommonBase { } } /** - * A length descriptor in the packet didn't describe the later data correctly + * A length descriptor in the packet didn't describe the later data correctly. */ public final static class BadLengthDescriptor extends DecodeError { private BadLengthDescriptor(long ptr, bindings.LDKDecodeError.BadLengthDescriptor obj) { @@ -89,7 +95,7 @@ public class DecodeError extends CommonBase { } } /** - * Error from std::io + * Error from [`std::io`]. */ public final static class Io extends DecodeError { public final org.ldk.enums.IOError io; @@ -106,6 +112,22 @@ public class DecodeError extends CommonBase { super(null, ptr); } } + /** + * Value is validly encoded but is dangerous to use. + * + * This is used for things like [`ChannelManager`] deserialization where we want to ensure + * that we don't use a [`ChannelManager`] which is in out of sync with the [`ChannelMonitor`]. + * This indicates that there is a critical implementation flaw in the storage implementation + * and it's unsafe to continue. + * + * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager + * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor + */ + public final static class DangerousValue extends DecodeError { + private DangerousValue(long ptr, bindings.LDKDecodeError.DangerousValue obj) { + super(null, ptr); + } + } long clone_ptr() { long ret = bindings.DecodeError_clone_ptr(this.ptr); Reference.reachabilityFence(this); @@ -202,12 +224,35 @@ public class DecodeError extends CommonBase { return ret_hu_conv; } + /** + * Utility method to constructs a new DangerousValue-variant DecodeError + */ + public static DecodeError dangerous_value() { + long ret = bindings.DecodeError_dangerous_value(); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.DecodeError ret_hu_conv = org.ldk.structs.DecodeError.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + return ret_hu_conv; + } + + /** + * Generates a non-cryptographic 64-bit hash of the DecodeError. + */ + public long hash() { + long ret = bindings.DecodeError_hash(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + @Override public int hashCode() { + return (int)this.hash(); + } /** * Checks if two DecodeErrors contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. */ public boolean eq(org.ldk.structs.DecodeError b) { - boolean ret = bindings.DecodeError_eq(this.ptr, b == null ? 0 : b.ptr); + boolean ret = bindings.DecodeError_eq(this.ptr, b.ptr); Reference.reachabilityFence(this); Reference.reachabilityFence(b); return ret; @@ -217,4 +262,13 @@ public class DecodeError extends CommonBase { if (!(o instanceof DecodeError)) return false; return this.eq((DecodeError)o); } + /** + * Get the string representation of a DecodeError object + */ + public String to_str() { + String ret = bindings.DecodeError_to_str(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + }