Subversion Repositories oidplus

Rev

Rev 846 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
827 daniel-mar 1
<?php
2
 
3
/**
4
 * ASN1 Signature Handler
5
 *
6
 * PHP version 5
7
 *
8
 * Handles signatures in the format described in
9
 * https://tools.ietf.org/html/rfc3279#section-2.2.2
10
 *
874 daniel-mar 11
 * @category  Crypt
12
 * @package   Common
827 daniel-mar 13
 * @author    Jim Wigginton <terrafrost@php.net>
14
 * @copyright 2016 Jim Wigginton
15
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
16
 * @link      http://phpseclib.sourceforge.net
17
 */
18
 
19
namespace phpseclib3\Crypt\DSA\Formats\Signature;
20
 
21
use phpseclib3\File\ASN1 as Encoder;
22
use phpseclib3\File\ASN1\Maps;
23
use phpseclib3\Math\BigInteger;
24
 
25
/**
26
 * ASN1 Signature Handler
27
 *
874 daniel-mar 28
 * @package Common
827 daniel-mar 29
 * @author  Jim Wigginton <terrafrost@php.net>
874 daniel-mar 30
 * @access  public
827 daniel-mar 31
 */
32
abstract class ASN1
33
{
34
    /**
35
     * Loads a signature
36
     *
874 daniel-mar 37
     * @access public
827 daniel-mar 38
     * @param string $sig
39
     * @return array|bool
40
     */
41
    public static function load($sig)
42
    {
43
        if (!is_string($sig)) {
44
            return false;
45
        }
46
 
47
        $decoded = Encoder::decodeBER($sig);
48
        if (empty($decoded)) {
49
            return false;
50
        }
51
        $components = Encoder::asn1map($decoded[0], Maps\DssSigValue::MAP);
52
 
53
        return $components;
54
    }
55
 
56
    /**
57
     * Returns a signature in the appropriate format
58
     *
874 daniel-mar 59
     * @access public
827 daniel-mar 60
     * @param \phpseclib3\Math\BigInteger $r
61
     * @param \phpseclib3\Math\BigInteger $s
62
     * @return string
63
     */
64
    public static function save(BigInteger $r, BigInteger $s)
65
    {
66
        return Encoder::encodeDER(compact('r', 's'), Maps\DssSigValue::MAP);
67
    }
68
}