1<?php
2/*
3 * Copyright 2008-2010 GuardTime AS
4 *
5 * This file is part of the GuardTime PHP SDK.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20/**
21 * @package asn1
22 */
23
24/**
25 * ASN.1 IA5String implementation.
26 *
27 * @package asn1
28 */
29class ASN1IA5String extends ASN1String {
30
31    /**
32     * Sets the value of this IA5String.
33     *
34     * Only ASCII 0 - 127 are allowed.
35     *
36     * @throws GTException
37     * @param  string $value the value
38     * @return void
39     */
40    protected function setValue($value) {
41
42        for ($i = 0; $i < strlen($value); $i++) {
43            $byte = ord($value{$i});
44
45            if ($byte < 0 || $byte > 127) {
46                throw new GTException("Invalid value in IA5String: {$byte}");
47            }
48
49        }
50
51        $this->value = $value;
52    }
53
54    /**
55     * Gets the ASN.1 type tag for this string.
56     *
57     * @return int ASN1_TAG_IA5_STRING
58     */
59    protected function getType() {
60        return ASN1_TAG_IA5_STRING;
61    }
62}
63
64?>
65