1414import de .rub .nds .protocol .constants .NamedEllipticCurveParameters ;
1515import de .rub .nds .protocol .constants .PointFormat ;
1616import de .rub .nds .protocol .crypto .CyclicGroup ;
17- import de .rub .nds .protocol .exception . PreparationException ;
17+ import de .rub .nds .protocol .util . SilentByteArrayOutputStream ;
1818import java .io .ByteArrayInputStream ;
19- import java .io .ByteArrayOutputStream ;
2019import java .io .IOException ;
2120import java .math .BigInteger ;
2221import org .apache .logging .log4j .LogManager ;
@@ -28,7 +27,7 @@ public class PointFormatter {
2827
2928 public static byte [] formatToByteArray (
3029 GroupParameters <?> groupParameters , Point point , PointFormat format ) {
31- ByteArrayOutputStream stream = new ByteArrayOutputStream ();
30+ SilentByteArrayOutputStream stream = new SilentByteArrayOutputStream ();
3231 if (point .isAtInfinity ()) {
3332 return new byte [1 ];
3433 }
@@ -40,16 +39,12 @@ public static byte[] formatToByteArray(
4039 switch (format ) {
4140 case UNCOMPRESSED :
4241 stream .write (0x04 );
43- try {
44- stream .write (
45- ArrayConverter .bigIntegerToNullPaddedByteArray (
46- point .getFieldX ().getData (), elementLength ));
47- stream .write (
48- ArrayConverter .bigIntegerToNullPaddedByteArray (
49- point .getFieldY ().getData (), elementLength ));
50- } catch (IOException ex ) {
51- throw new PreparationException ("Could not serialize ec point" , ex );
52- }
42+ stream .write (
43+ ArrayConverter .bigIntegerToNullPaddedByteArray (
44+ point .getFieldX ().getData (), elementLength ));
45+ stream .write (
46+ ArrayConverter .bigIntegerToNullPaddedByteArray (
47+ point .getFieldY ().getData (), elementLength ));
5348 return stream .toByteArray ();
5449 case COMPRESSED :
5550 CyclicGroup <?> group = groupParameters .getGroup ();
@@ -66,47 +61,35 @@ public static byte[] formatToByteArray(
6661 } else {
6762 stream .write (0x02 );
6863 }
69- try {
70- stream .write (
71- ArrayConverter .bigIntegerToNullPaddedByteArray (
72- point .getFieldX ().getData (), elementLength ));
73- } catch (IOException ex ) {
74- throw new PreparationException ("Could not serialize ec point" , ex );
75- }
64+ stream .write (
65+ ArrayConverter .bigIntegerToNullPaddedByteArray (
66+ point .getFieldX ().getData (), elementLength ));
7667 return stream .toByteArray ();
7768 default :
7869 throw new UnsupportedOperationException ("Unsupported PointFormat: " + format );
7970 }
8071 } else {
81- try {
82- byte [] coordinate =
83- ArrayConverter .bigIntegerToNullPaddedByteArray (
84- point .getFieldX ().getData (), elementLength );
85- stream .write (coordinate );
86- } catch (IOException ex ) {
87- throw new PreparationException ("Could not serialize ec point" , ex );
88- }
72+ byte [] coordinate =
73+ ArrayConverter .bigIntegerToNullPaddedByteArray (
74+ point .getFieldX ().getData (), elementLength );
75+ stream .write (coordinate );
8976 return stream .toByteArray ();
9077 }
9178 }
9279
9380 public static byte [] toRawFormat (Point point ) {
94- ByteArrayOutputStream stream = new ByteArrayOutputStream ();
81+ SilentByteArrayOutputStream stream = new SilentByteArrayOutputStream ();
9582 if (point .isAtInfinity ()) {
9683 return new byte [1 ];
9784 }
9885 int elementLength =
9986 ArrayConverter .bigIntegerToByteArray (point .getFieldX ().getModulus ()).length ;
100- try {
101- stream .write (
102- ArrayConverter .bigIntegerToNullPaddedByteArray (
103- point .getFieldX ().getData (), elementLength ));
104- stream .write (
105- ArrayConverter .bigIntegerToNullPaddedByteArray (
106- point .getFieldY ().getData (), elementLength ));
107- } catch (IOException ex ) {
108- throw new PreparationException ("Could not serialize ec point" , ex );
109- }
87+ stream .write (
88+ ArrayConverter .bigIntegerToNullPaddedByteArray (
89+ point .getFieldX ().getData (), elementLength ));
90+ stream .write (
91+ ArrayConverter .bigIntegerToNullPaddedByteArray (
92+ point .getFieldY ().getData (), elementLength ));
11093 return stream .toByteArray ();
11194 }
11295
0 commit comments