# Class Encoding

java.lang.Object
org.mariadb.jdbc.internal.com.send.authentication.ed25519.math.Encoding

Direct Known Subclasses:
  `Ed25519LittleEndianEncoding`

public abstract class Encoding extends Object
Common interface for all $(b-1)$-bit encodings of elements of EdDSA finite fields.

Author:
  str4d

## Field Summary

Fields
Modifier and Type
Field
Description
`protected Field`
`f`

## Constructor Summary

Constructors
Constructor
Description
`Encoding()`

## Method Summary

Modifier and Type
Method
Description
`abstract FieldElement`
`decode(byte[] in)`
Decode a FieldElement from its $(b-1)$-bit encoding.
`abstract byte[]`
`encode(FieldElement x)`
Encode a FieldElement in its $(b-1)$-bit encoding.
`abstract boolean`
`isNegative(FieldElement x)`
From the Ed25519 paper:
$x$ is negative if the $(b-1)$-bit encoding of $x$ is lexicographically larger than the $(b-1)$-bit encoding of -x.
`void`
`setField(Field f)`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### f

protected Field f

## Constructor Details

### Encoding

public Encoding()

## Method Details

### setField

public void setField(Field f)

### encode

public abstract byte[] encode(FieldElement x)
Encode a FieldElement in its $(b-1)$-bit encoding.

Parameters:
  `x` - the FieldElement to encode
Returns:
  the $(b-1)$-bit encoding of this FieldElement.

### decode

public abstract FieldElement decode(byte[] in)
Decode a FieldElement from its $(b-1)$-bit encoding. The highest bit is masked out.

Parameters:
  `in` - the $(b-1)$-bit encoding of a FieldElement.
Returns:
  the FieldElement represented by 'val'.

### isNegative

public abstract boolean isNegative(FieldElement x)
From the Ed25519 paper:
$x$ is negative if the $(b-1)$-bit encoding of $x$ is lexicographically larger than the $(b-1)$-bit encoding of -x. If $q$ is an odd prime and the encoding is the little-endian representation of $\{0, 1,\dots, q-1\}$ then the negative elements of $F_q$ are $\{1, 3, 5,\dots, q-2\}$.

Parameters:
  `x` - the FieldElement to check
Returns:
  true if negative