15ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler/* 25ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * Copyright (C) 2014 The Android Open Source Project 35ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * 45ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * Licensed under the Apache License, Version 2.0 (the "License"); 55ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * you may not use this file except in compliance with the License. 65ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * You may obtain a copy of the License at 75ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * 85ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * http://www.apache.org/licenses/LICENSE-2.0 95ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * 105ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * Unless required by applicable law or agreed to in writing, software 115ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * distributed under the License is distributed on an "AS IS" BASIS, 125ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * See the License for the specific language governing permissions and 145ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * limitations under the License. 155ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler */ 165ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittlerpackage libcore.tlswire.handshake; 175ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler/** 185ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler * {@code CompressionMethod} enum from TLS 1.2 RFC 5246. 195ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler */ 205ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittlerpublic class CompressionMethod { 215ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler public static final CompressionMethod NULL = new CompressionMethod(0, "null"); 225ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler public static final CompressionMethod DEFLATE = new CompressionMethod(1, "deflate"); 235ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler public final int type; 245ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler public final String name; 255ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler private CompressionMethod(int type, String name) { 265ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler this.type = type; 275ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler this.name = name; 285ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler } 295ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler public static CompressionMethod valueOf(int type) { 305ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler switch (type) { 315ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler case 0: 325ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler return NULL; 335ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler case 1: 345ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler return DEFLATE; 355ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler default: 365ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler return new CompressionMethod(type, String.valueOf(type)); 375ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler } 385ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler } 395ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler @Override 405ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler public String toString() { 415ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler return name; 425ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler } 435ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler @Override 445ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler public int hashCode() { 455ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler final int prime = 31; 465ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler int result = 1; 475ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler result = prime * result + type; 485ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler return result; 495ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler } 505ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler @Override 515ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler public boolean equals(Object obj) { 525ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler if (this == obj) { 535ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler return true; 545ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler } 555ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler if (obj == null) { 565ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler return false; 575ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler } 585ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler if (getClass() != obj.getClass()) { 595ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler return false; 605ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler } 615ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler CompressionMethod other = (CompressionMethod) obj; 625ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler if (type != other.type) { 635ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler return false; 645ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler } 655ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler return true; 665ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler } 675ca87050dafe566d8d4e2b11e395f7d06a2d837bNathan Mittler} 68