0N/A/*
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A *
0N/A * (C) Copyright IBM Corp. 1999 All Rights Reserved.
0N/A * Copyright 1997 The Open Group Research Institute. All rights reserved.
0N/A */
0N/A
0N/Apackage sun.security.krb5.internal.ktab;
0N/A
0N/Aimport sun.security.krb5.internal.*;
0N/Aimport sun.security.krb5.internal.util.KrbDataOutputStream;
0N/Aimport java.io.IOException;
0N/Aimport java.io.FileOutputStream;
0N/Aimport java.io.OutputStream;
0N/Aimport java.io.UnsupportedEncodingException;
0N/A
0N/A/**
0N/A * This class implements a buffered input stream. It is used for parsing key table
0N/A * data to memory.
0N/A *
0N/A * @author Yanni Zhang
0N/A *
0N/A */
0N/Apublic class KeyTabOutputStream extends KrbDataOutputStream implements KeyTabConstants {
0N/A private KeyTabEntry entry;
0N/A private int keyType;
0N/A private byte[] keyValue;
0N/A public int version;
0N/A
0N/A public KeyTabOutputStream(OutputStream os) {
0N/A super(os);
0N/A }
0N/A
0N/A public void writeVersion(int num) throws IOException {
0N/A version = num;
0N/A write16(num); //we use the standard version.
0N/A }
0N/A
0N/A public void writeEntry(KeyTabEntry entry) throws IOException {
0N/A write32(entry.entryLength());
0N/A String[] serviceNames = entry.service.getNameStrings();
0N/A int comp_num = serviceNames.length;
0N/A if (version == KRB5_KT_VNO_1) {
0N/A write16(comp_num + 1);
0N/A }
0N/A else write16(comp_num);
0N/A
0N/A byte[] realm = null;
0N/A try {
0N/A realm = entry.service.getRealmString().getBytes("8859_1");
0N/A } catch (UnsupportedEncodingException exc) {
0N/A }
0N/A
0N/A write16(realm.length);
0N/A write(realm);
0N/A for (int i = 0; i < comp_num; i++) {
0N/A try {
0N/A write16(serviceNames[i].getBytes("8859_1").length);
0N/A write(serviceNames[i].getBytes("8859_1"));
0N/A } catch (UnsupportedEncodingException exc) {
0N/A }
0N/A }
0N/A write32(entry.service.getNameType());
0N/A //time is long, but we only use 4 bytes to store the data.
0N/A write32((int)(entry.timestamp.getTime()/1000));
0N/A
0N/A // the key version might be a 32 bit extended number.
0N/A write8(entry.keyVersion % 256 );
0N/A write16(entry.keyType);
0N/A write16(entry.keyblock.length);
0N/A write(entry.keyblock);
0N/A
0N/A // if the key version isn't smaller than 256, it could be saved as
0N/A // extension key version number in 4 bytes. The nonzero extension
0N/A // key version number will be trusted. However, it isn't standardized
0N/A // yet, we won't support it.
0N/A // if (entry.keyVersion >= 256) {
0N/A // write32(entry.keyVersion);
0N/A //}
0N/A }
0N/A}