(byte[] jose, int coordLen)
| 418 | } |
| 419 | |
| 420 | private static byte[] joseToDerEcdsa(byte[] jose, int coordLen) { |
| 421 | if (jose.length != coordLen * 2) { |
| 422 | throw new CryptoException("bad ECDSA JOSE signature length"); |
| 423 | } |
| 424 | byte[] r = trimAndAddSignByte(jose, 0, coordLen); |
| 425 | byte[] s = trimAndAddSignByte(jose, coordLen, coordLen); |
| 426 | int seqLen = 2 + r.length + 2 + s.length; |
| 427 | byte[] out; |
| 428 | if (seqLen < 128) { |
| 429 | out = new byte[2 + seqLen]; |
| 430 | out[0] = 0x30; |
| 431 | out[1] = (byte) seqLen; |
| 432 | int p = 2; |
| 433 | out[p++] = 0x02; out[p++] = (byte) r.length; |
| 434 | System.arraycopy(r, 0, out, p, r.length); p += r.length; |
| 435 | out[p++] = 0x02; out[p++] = (byte) s.length; |
| 436 | System.arraycopy(s, 0, out, p, s.length); |
| 437 | } else { |
| 438 | // 0x81 length form |
| 439 | out = new byte[3 + seqLen]; |
| 440 | out[0] = 0x30; |
| 441 | out[1] = (byte) 0x81; |
| 442 | out[2] = (byte) seqLen; |
| 443 | int p = 3; |
| 444 | out[p++] = 0x02; out[p++] = (byte) r.length; |
| 445 | System.arraycopy(r, 0, out, p, r.length); p += r.length; |
| 446 | out[p++] = 0x02; out[p++] = (byte) s.length; |
| 447 | System.arraycopy(s, 0, out, p, s.length); |
| 448 | } |
| 449 | return out; |
| 450 | } |
| 451 | |
| 452 | private static byte[] trimAndAddSignByte(byte[] src, int off, int len) { |
| 453 | int start = off; |
no test coverage detected