2 * Copyright (C) 2001 Nikos Mavroyanopoulos
4 * This file is part of GNUTLS.
6 * The GNUTLS library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "gnutls_int.h"
23 #include "gnutls_errors.h"
24 #include "gnutls_num.h"
25 #include "ext_max_record.h"
28 * In case of a server: if a MAX_RECORD_SIZE extension type is received then it stores
29 * into the state the new value. The server may use gnutls_get_max_record_size(),
30 * in order to access it.
32 * In case of a client: If a different max record size (than the default) has
33 * been specified then it sends the extension.
37 int _gnutls_max_record_recv_params( GNUTLS_STATE state
, const opaque
* data
, int data_size
) {
40 if (state
->security_parameters
.entity
== GNUTLS_SERVER
) {
42 if ( data_size
!= 1) {
44 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH
;
47 new_size
= _gnutls_mre_num2record(data
[0]);
54 state
->security_parameters
.max_record_size
= new_size
;
56 } else { /* CLIENT SIDE - we must check if the sent record size is the right one
60 if ( data_size
!= 1) {
62 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH
;
65 new_size
= _gnutls_mre_num2record(data
[0]);
67 if (new_size
< 0 || new_size
!= state
->gnutls_internals
.proposed_record_size
) {
69 return GNUTLS_E_ILLEGAL_PARAMETER
;
71 state
->security_parameters
.max_record_size
= state
->gnutls_internals
.proposed_record_size
;
81 /* returns data_size or a negative number on failure
82 * data is allocated localy
84 int _gnutls_max_record_send_params( GNUTLS_STATE state
, opaque
* data
, int data_size
) {
86 /* this function sends the client extension data (dnsname) */
87 if (state
->security_parameters
.entity
== GNUTLS_CLIENT
) {
89 if (state
->gnutls_internals
.proposed_record_size
!= DEFAULT_MAX_RECORD_SIZE
) {
93 if (data_size
< len
) {
95 return GNUTLS_E_INVALID_REQUEST
;
98 data
[0] = _gnutls_mre_record2num( state
->gnutls_internals
.proposed_record_size
);
102 } else { /* server side */
104 if (state
->security_parameters
.max_record_size
!= DEFAULT_MAX_RECORD_SIZE
) {
106 if (data_size
< len
) {
108 return GNUTLS_E_INVALID_REQUEST
;
111 data
[0] = _gnutls_mre_record2num( state
->security_parameters
.max_record_size
);
121 /* Maps numbers to record sizes according to the
124 int _gnutls_mre_num2record( int num
) {
135 return GNUTLS_E_ILLEGAL_PARAMETER
;
139 /* Maps record size to numbers according to the
142 int _gnutls_mre_record2num( int record_size
) {
143 switch(record_size
) {
153 return GNUTLS_E_ILLEGAL_PARAMETER
;